mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-20 02:47:34 +03:00
Done updating rendering performance for now. Further changes would require more fundamental work, I'm still not really happy with it as is though. Will probably take a few hours to clean the code though.
This commit is contained in:
parent
005e2cb2be
commit
ef1a32ee92
@ -7,11 +7,11 @@ use alacritty_terminal::{
|
|||||||
event_loop::{EventLoop, Msg, Notifier},
|
event_loop::{EventLoop, Msg, Notifier},
|
||||||
grid::Scroll,
|
grid::Scroll,
|
||||||
index::{Direction, Point},
|
index::{Direction, Point},
|
||||||
selection::{Selection, SelectionRange, SelectionType},
|
selection::{Selection, SelectionType},
|
||||||
sync::FairMutex,
|
sync::FairMutex,
|
||||||
term::{cell::Cell, RenderableCursor, SizeInfo, TermMode},
|
term::{RenderableContent, SizeInfo, TermMode},
|
||||||
tty::{self, setup_env},
|
tty::{self, setup_env},
|
||||||
Grid, Term,
|
Term,
|
||||||
};
|
};
|
||||||
use futures::{
|
use futures::{
|
||||||
channel::mpsc::{unbounded, UnboundedSender},
|
channel::mpsc::{unbounded, UnboundedSender},
|
||||||
@ -54,7 +54,7 @@ pub enum TerminalConnection {
|
|||||||
Disconnected {
|
Disconnected {
|
||||||
directory: Option<PathBuf>,
|
directory: Option<PathBuf>,
|
||||||
shell: Option<Shell>,
|
shell: Option<Shell>,
|
||||||
error: std::io::Error,
|
error: Option<std::io::Error>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,15 +107,23 @@ impl TerminalConnection {
|
|||||||
return TerminalConnection::Disconnected {
|
return TerminalConnection::Disconnected {
|
||||||
directory: working_directory,
|
directory: working_directory,
|
||||||
shell,
|
shell,
|
||||||
error,
|
error: Some(error),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let shell_txt = {
|
let shell_txt = {
|
||||||
|
match shell {
|
||||||
|
Some(Shell::System) | None => {
|
||||||
let mut buf = [0; 1024];
|
let mut buf = [0; 1024];
|
||||||
let pw = alacritty_unix::get_pw_entry(&mut buf).unwrap();
|
let pw = alacritty_unix::get_pw_entry(&mut buf).unwrap();
|
||||||
pw.shell.to_string()
|
pw.shell.to_string()
|
||||||
|
}
|
||||||
|
Some(Shell::Program(program)) => program,
|
||||||
|
Some(Shell::WithArguments { program, args }) => {
|
||||||
|
format!("{} {}", program, args.join(" "))
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//And connect them together
|
//And connect them together
|
||||||
@ -292,23 +300,29 @@ impl Terminal {
|
|||||||
self.term.lock().selection = sel;
|
self.term.lock().selection = sel;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn grid(&self) -> Grid<Cell> {
|
pub fn render_lock<F, T>(&self, new_size: Option<SizeInfo>, f: F) -> T
|
||||||
let term = self.term.lock();
|
where
|
||||||
term.grid().clone() //TODO: BAD!!!!!!!!
|
F: FnOnce(RenderableContent) -> T,
|
||||||
|
{
|
||||||
|
if let Some(new_size) = new_size {
|
||||||
|
self.pty_tx.0.send(Msg::Resize(new_size)).ok(); //Give the PTY a chance to react to the new size
|
||||||
|
//TODO: Is this bad for performance?
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut term = self.term.lock(); //Lock
|
||||||
|
|
||||||
|
if let Some(new_size) = new_size {
|
||||||
|
term.resize(new_size); //Reflow
|
||||||
|
}
|
||||||
|
|
||||||
|
let content = term.renderable_content();
|
||||||
|
f(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_display_offset(&self) -> usize {
|
pub fn get_display_offset(&self) -> usize {
|
||||||
self.term.lock().renderable_content().display_offset
|
self.term.lock().renderable_content().display_offset
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_selection(&self) -> Option<SelectionRange> {
|
|
||||||
self.term.lock().renderable_content().selection //TODO: BAD!!!!!
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_cursor(&self) -> RenderableCursor {
|
|
||||||
self.term.lock().renderable_content().cursor
|
|
||||||
}
|
|
||||||
|
|
||||||
///Scroll the terminal
|
///Scroll the terminal
|
||||||
pub fn scroll(&self, scroll: Scroll) {
|
pub fn scroll(&self, scroll: Scroll) {
|
||||||
self.term.lock().scroll_display(scroll)
|
self.term.lock().scroll_display(scroll)
|
||||||
|
@ -364,10 +364,12 @@ fn get_wd_for_workspace(workspace: &Workspace, cx: &AppContext) -> Option<PathBu
|
|||||||
WorkingDirectory::CurrentProjectDirectory => current_project_directory(workspace, cx),
|
WorkingDirectory::CurrentProjectDirectory => current_project_directory(workspace, cx),
|
||||||
WorkingDirectory::FirstProjectDirectory => first_project_directory(workspace, cx),
|
WorkingDirectory::FirstProjectDirectory => first_project_directory(workspace, cx),
|
||||||
WorkingDirectory::AlwaysHome => None,
|
WorkingDirectory::AlwaysHome => None,
|
||||||
WorkingDirectory::Always { directory } => shellexpand::full(&directory)
|
WorkingDirectory::Always { directory } => {
|
||||||
|
shellexpand::full(&directory) //TODO handle this better
|
||||||
.ok()
|
.ok()
|
||||||
.map(|dir| Path::new(&dir.to_string()).to_path_buf())
|
.map(|dir| Path::new(&dir.to_string()).to_path_buf())
|
||||||
.filter(|dir| dir.is_dir()),
|
.filter(|dir| dir.is_dir())
|
||||||
|
}
|
||||||
};
|
};
|
||||||
res.or_else(|| home_dir())
|
res.or_else(|| home_dir())
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ use alacritty_terminal::{
|
|||||||
cell::{Cell, Flags},
|
cell::{Cell, Flags},
|
||||||
SizeInfo,
|
SizeInfo,
|
||||||
},
|
},
|
||||||
Grid,
|
|
||||||
};
|
};
|
||||||
use editor::{Cursor, CursorShape, HighlightedRange, HighlightedRangeLine};
|
use editor::{Cursor, CursorShape, HighlightedRange, HighlightedRangeLine};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
@ -282,42 +281,41 @@ impl Element for TerminalEl {
|
|||||||
) -> (gpui::geometry::vector::Vector2F, Self::LayoutState) {
|
) -> (gpui::geometry::vector::Vector2F, Self::LayoutState) {
|
||||||
let tcx = TerminalLayoutTheme::new(cx.global::<Settings>(), &cx.font_cache());
|
let tcx = TerminalLayoutTheme::new(cx.global::<Settings>(), &cx.font_cache());
|
||||||
|
|
||||||
|
//This locks the terminal, so resize it first.
|
||||||
|
//Layout grid cells
|
||||||
|
let cur_size = make_new_size(constraint, &tcx.cell_width, &tcx.line_height);
|
||||||
|
|
||||||
let terminal = self
|
let terminal = self
|
||||||
.connection
|
.connection
|
||||||
.upgrade(cx)
|
.upgrade(cx)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.read(cx)
|
.read(cx)
|
||||||
.get_terminal() //TODO!
|
.get_terminal()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
//This locks the terminal, so resize it first.
|
|
||||||
let cur_size = make_new_size(constraint, &tcx.cell_width, &tcx.line_height);
|
|
||||||
terminal.set_size(cur_size);
|
|
||||||
|
|
||||||
let grid = terminal.grid();
|
|
||||||
let selection = terminal.get_selection();
|
|
||||||
let display_offset = terminal.get_display_offset();
|
|
||||||
let cursor = terminal.get_cursor();
|
|
||||||
//Layout grid cells
|
|
||||||
|
|
||||||
|
let (cursor, cells, rects, highlights) = terminal.render_lock(Some(cur_size), |content| {
|
||||||
let (cells, rects, highlights) = layout_grid(
|
let (cells, rects, highlights) = layout_grid(
|
||||||
grid.display_iter(),
|
content.display_iter,
|
||||||
&tcx.text_style,
|
&tcx.text_style,
|
||||||
tcx.terminal_theme,
|
tcx.terminal_theme,
|
||||||
cx.text_layout_cache,
|
cx.text_layout_cache,
|
||||||
self.modal,
|
self.modal,
|
||||||
selection,
|
content.selection,
|
||||||
);
|
);
|
||||||
|
|
||||||
//Layout cursor
|
//Layout cursor
|
||||||
let cursor = layout_cursor(
|
let cursor = layout_cursor(
|
||||||
&grid,
|
// grid,
|
||||||
cx.text_layout_cache,
|
cx.text_layout_cache,
|
||||||
&tcx,
|
&tcx,
|
||||||
cursor.point,
|
content.cursor.point,
|
||||||
display_offset,
|
content.display_offset,
|
||||||
constraint,
|
constraint,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
(cursor, cells, rects, highlights)
|
||||||
|
});
|
||||||
|
|
||||||
//Select background color
|
//Select background color
|
||||||
let background_color = if self.modal {
|
let background_color = if self.modal {
|
||||||
tcx.terminal_theme.colors.modal_background
|
tcx.terminal_theme.colors.modal_background
|
||||||
@ -406,6 +404,7 @@ impl Element for TerminalEl {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Draw the text cells
|
||||||
cx.paint_layer(clip_bounds, |cx| {
|
cx.paint_layer(clip_bounds, |cx| {
|
||||||
for cell in &layout.cells {
|
for cell in &layout.cells {
|
||||||
cell.paint(origin, layout, visible_bounds, cx);
|
cell.paint(origin, layout, visible_bounds, cx);
|
||||||
@ -484,15 +483,16 @@ impl Element for TerminalEl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///TODO: Fix cursor rendering with alacritty fork
|
||||||
fn layout_cursor(
|
fn layout_cursor(
|
||||||
grid: &Grid<Cell>,
|
// grid: &Grid<Cell>,
|
||||||
text_layout_cache: &TextLayoutCache,
|
text_layout_cache: &TextLayoutCache,
|
||||||
tcx: &TerminalLayoutTheme,
|
tcx: &TerminalLayoutTheme,
|
||||||
cursor_point: Point,
|
cursor_point: Point,
|
||||||
display_offset: usize,
|
display_offset: usize,
|
||||||
constraint: SizeConstraint,
|
constraint: SizeConstraint,
|
||||||
) -> Option<Cursor> {
|
) -> Option<Cursor> {
|
||||||
let cursor_text = layout_cursor_text(grid, text_layout_cache, tcx);
|
let cursor_text = layout_cursor_text(/*grid,*/ cursor_point, text_layout_cache, tcx);
|
||||||
get_cursor_shape(
|
get_cursor_shape(
|
||||||
cursor_point.line.0 as usize,
|
cursor_point.line.0 as usize,
|
||||||
cursor_point.column.0 as usize,
|
cursor_point.column.0 as usize,
|
||||||
@ -521,12 +521,12 @@ fn layout_cursor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn layout_cursor_text(
|
fn layout_cursor_text(
|
||||||
grid: &Grid<Cell>,
|
// grid: &Grid<Cell>,
|
||||||
|
_cursor_point: Point,
|
||||||
text_layout_cache: &TextLayoutCache,
|
text_layout_cache: &TextLayoutCache,
|
||||||
tcx: &TerminalLayoutTheme,
|
tcx: &TerminalLayoutTheme,
|
||||||
) -> Line {
|
) -> Line {
|
||||||
let cursor_point = grid.cursor.point;
|
let cursor_text = " "; //grid[cursor_point.line][cursor_point.column].c.to_string();
|
||||||
let cursor_text = grid[cursor_point.line][cursor_point.column].c.to_string();
|
|
||||||
|
|
||||||
text_layout_cache.layout_str(
|
text_layout_cache.layout_str(
|
||||||
&cursor_text,
|
&cursor_text,
|
||||||
|
@ -61,13 +61,17 @@ impl<'a> TerminalTestContext<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn grid_as_str(connection: &TerminalConnection) -> String {
|
fn grid_as_str(connection: &TerminalConnection) -> String {
|
||||||
let grid = connection.get_terminal().unwrap().grid();
|
connection
|
||||||
let lines = grid.display_iter().group_by(|i| i.point.line.0);
|
.get_terminal()
|
||||||
|
.unwrap()
|
||||||
|
.render_lock(None, |content| {
|
||||||
|
let lines = content.display_iter.group_by(|i| i.point.line.0);
|
||||||
lines
|
lines
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(_, line)| line.map(|i| i.c).collect::<String>())
|
.map(|(_, line)| line.map(|i| i.c).collect::<String>())
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join("\n")
|
.join("\n")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user