diff --git a/src/main.rs b/src/main.rs index 6eb464a..892a806 100644 --- a/src/main.rs +++ b/src/main.rs @@ -666,7 +666,7 @@ impl Application for App { TermEvent::MouseCursorDirty | TermEvent::Wakeup => { if let Some(terminal) = self.tab_model.data::>(entity) { let mut terminal = terminal.lock().unwrap(); - terminal.update(); + terminal.needs_update = true; } } _ => { diff --git a/src/terminal.rs b/src/terminal.rs index 910d2bf..df49a54 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -123,6 +123,7 @@ pub struct Terminal { colors: Colors, notifier: Notifier, pub context_menu: Option, + pub needs_update: bool, } impl Terminal { @@ -182,6 +183,7 @@ impl Terminal { term, notifier, context_menu: None, + needs_update: true, } } diff --git a/src/terminal_box.rs b/src/terminal_box.rs index 673a8dc..13b5214 100644 --- a/src/terminal_box.rs +++ b/src/terminal_box.rs @@ -117,12 +117,22 @@ where let limits = limits.width(Length::Fill).height(Length::Fill); let mut terminal = self.terminal.lock().unwrap(); + //TODO: set size? + + // Update if needed + if terminal.needs_update { + terminal.update(); + terminal.needs_update = false; + } + + // Ensure terminal is shaped terminal.with_buffer_mut(|buffer| { let mut font_system = font_system().write().unwrap(); buffer.shape_until_scroll(font_system.raw(), true); }); + // Calculate layout lines terminal.with_buffer(|buffer| { let mut layout_lines = 0; for line in buffer.lines.iter() { @@ -182,8 +192,6 @@ where let state = tree.state.downcast_ref::(); - let mut terminal = self.terminal.lock().unwrap(); - //TODO: make this configurable let scrollbar_w = 8.0; @@ -200,9 +208,17 @@ where return; } + let mut terminal = self.terminal.lock().unwrap(); + // Ensure terminal is the right size terminal.resize(view_w as u32, view_h as u32); + // Update if needed + if terminal.needs_update { + terminal.update(); + terminal.needs_update = false; + } + // Ensure terminal is shaped terminal.with_buffer_mut(|buffer| { let mut font_system = font_system().write().unwrap(); @@ -337,7 +353,7 @@ where } let duration = instant.elapsed(); - log::debug!("redraw {}, {}: {:?}", view_w, view_h, duration); + log::trace!("redraw {}, {}: {:?}", view_w, view_h, duration); } fn on_event(