Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toward enable should_render (fix pane render) #318

Merged
merged 11 commits into from
Apr 30, 2021
12 changes: 7 additions & 5 deletions src/client/panes/terminal_pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ impl Pane for TerminalPane {
for byte in bytes.iter() {
self.vte_parser.advance(&mut self.grid, *byte);
}
self.set_should_render(true);
}
fn cursor_coordinates(&self) -> Option<(usize, usize)> {
// (x, y)
Expand Down Expand Up @@ -160,7 +161,7 @@ impl Pane for TerminalPane {
// around
// 2. When there are wide characters in a pane, since we don't yet handle them properly,
// the spill over to the pane to the right
// if self.should_render || cfg!(test) {
// if self.should_render() {
if true {
let mut vte_output = String::new();
let buffer_lines = &self.read_buffer_as_lines();
Expand Down Expand Up @@ -203,7 +204,7 @@ impl Pane for TerminalPane {
}
character_styles.clear();
}
self.grid.should_render = false;
self.set_should_render(false);
Some(vte_output)
} else {
None
Expand Down Expand Up @@ -262,15 +263,15 @@ impl Pane for TerminalPane {
}
fn scroll_up(&mut self, count: usize) {
self.grid.move_viewport_up(count);
self.grid.should_render = true;
self.set_should_render(true);
}
fn scroll_down(&mut self, count: usize) {
self.grid.move_viewport_down(count);
self.grid.should_render = true;
self.set_should_render(true);
}
fn clear_scroll(&mut self) {
self.grid.reset_viewport();
self.grid.should_render = true;
self.set_should_render(true);
}
}

Expand Down Expand Up @@ -315,6 +316,7 @@ impl TerminalPane {
let rows = self.get_rows();
let columns = self.get_columns();
self.grid.change_size(rows, columns);
self.set_should_render(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elegant!

}
pub fn read_buffer_as_lines(&self) -> Vec<Vec<TerminalCharacter>> {
self.grid.as_character_lines()
Expand Down
5 changes: 5 additions & 0 deletions src/client/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,11 @@ impl Tab {
pub fn toggle_fullscreen_is_active(&mut self) {
self.fullscreen_is_active = !self.fullscreen_is_active;
}
pub fn set_force_render(&mut self) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I would have gone with something on the state of Tab that bypasses the should_render of each pane, but the more I think about it, the more I like this solution.

for pane in self.panes.values_mut() {
pane.set_should_render(true);
}
}
pub fn render(&mut self) {
if self.active_terminal.is_none() {
// we might not have an active terminal if we closed the last pane
Expand Down
14 changes: 9 additions & 5 deletions src/common/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ impl Screen {
let active_tab_pos = self.get_active_tab().unwrap().position;
let new_tab_pos = (active_tab_pos + 1) % self.tabs.len();

for tab in self.tabs.values() {
for tab in self.tabs.values_mut() {
if tab.position == new_tab_pos {
tab.set_force_render();
self.active_tab_index = Some(tab.index);
break;
}
Expand All @@ -168,8 +169,9 @@ impl Screen {
} else {
active_tab_pos - 1
};
for tab in self.tabs.values() {
for tab in self.tabs.values_mut() {
if tab.position == new_tab_pos {
tab.set_force_render();
self.active_tab_index = Some(tab.index);
break;
}
Expand All @@ -180,9 +182,10 @@ impl Screen {

pub fn go_to_tab(&mut self, mut tab_index: usize) {
tab_index -= 1;
let active_tab = self.get_active_tab().unwrap();
if let Some(t) = self.tabs.values().find(|t| t.position == tab_index) {
if t.index != active_tab.index {
let active_tab_index = self.get_active_tab().unwrap().index;
if let Some(t) = self.tabs.values_mut().find(|t| t.position == tab_index) {
if t.index != active_tab_index {
t.set_force_render();
self.active_tab_index = Some(t.index);
self.update_tabs();
self.render();
Expand Down Expand Up @@ -226,6 +229,7 @@ impl Screen {
for (_, tab) in self.tabs.iter_mut() {
tab.resize_whole_tab(new_screen_size);
}
let _ = self.get_active_tab_mut().map(|t| t.set_force_render());
self.render();
}

Expand Down