diff --git a/src/lib.rs b/src/lib.rs index 272bf0c..b3a6373 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ use std::io::{self, stdin, stdout, Write}; use std::sync::mpsc::channel; +use std::time::{Duration, Instant}; use std::{env, thread}; use termion::event::{Event, Key, MouseButton, MouseEvent}; @@ -27,6 +28,9 @@ struct Multiview { /// Whether we need to refresh the UI. pub refresh_ui: bool, + + /// Last time when the rendering was performed. + pub last_render: Instant, } impl Multiview { @@ -37,6 +41,7 @@ impl Multiview { tiles, selected: (0, 0), refresh_ui: true, + last_render: Instant::now(), }; write!( @@ -85,6 +90,13 @@ impl Multiview { /// Renders all the tiles of the multiview. pub fn render(&mut self) -> io::Result<()> { + let now = Instant::now(); + + if now.duration_since(self.last_render) < Duration::from_millis(20) { + return Ok(()); + } + + self.last_render = now; let mut buffer = vec![]; for i in 0..self.tiles.len() { for j in 0..self.tiles[0].len() { diff --git a/src/tile.rs b/src/tile.rs index 014fa17..058e224 100644 --- a/src/tile.rs +++ b/src/tile.rs @@ -249,7 +249,6 @@ impl Tile { /// Push content into the stdout of the tile. pub fn push_stdout(&mut self, content: String) { eprintln!("{:?}", content); - for c in content.chars() { if c == '\x1b' { self.counting = false; @@ -363,7 +362,7 @@ impl Tile { .stdout .iter() .skip(scroll as usize) - .take((h + scroll) as usize); + .take(h as usize + 1); let mut line = iter.next().unwrap(); let mut char_iter = line.chars();