diff --git a/src/model.rs b/src/model.rs index 68f3e9b..9461eec 100644 --- a/src/model.rs +++ b/src/model.rs @@ -40,7 +40,7 @@ impl Config { let cfg: crate::config::Config = serde_yaml::from_str(&data)?; Ok(Self { - output: Arc::new(Mutex::new(output::Controller::new("==> ".to_owned(), 10))), + output: Arc::new(Mutex::new(output::Controller::new("==> ".to_owned()))), chains: cfg.chains, env: if let Some(e) = cfg.env { e diff --git a/src/output.rs b/src/output.rs index e90b25d..952aeb8 100644 --- a/src/output.rs +++ b/src/output.rs @@ -1,54 +1,30 @@ -use std::{ - error::Error, - io::Write, - result::Result, -}; +use std::{error::Error, io::Write, result::Result}; -use crossterm::{ - style::Print, - terminal, - QueueableCommand, -}; +use crossterm::{style::Print, QueueableCommand}; pub(crate) struct Controller { + pending_lines: Vec, prefix: String, - max_lines: usize, - lines: Vec, - drawn_lines: usize, } + impl Controller { - pub fn new(prefix: String, max: usize) -> Self { + pub fn new(prefix: String) -> Self { Self { prefix, - max_lines: max, - drawn_lines: 0, - lines: Vec::::with_capacity(max + 1), + pending_lines: vec![], } } pub fn append(&mut self, s: String) { - self.lines.push(s); - if self.lines.len() > self.max_lines { - self.lines.remove(0); - } + self.pending_lines.push(s); } pub fn draw(&mut self) -> Result<(), Box> { let mut stdout = std::io::stdout(); - if self.drawn_lines > 0 { - stdout - .queue(crossterm::cursor::MoveToColumn(0u16)) - .unwrap() - .queue(crossterm::cursor::MoveUp(self.drawn_lines as u16)) - .unwrap(); - } - stdout.queue(terminal::Clear(terminal::ClearType::FromCursorDown))?; - - for l in &self.lines { + for l in &self.pending_lines { stdout.queue(Print(format!("{}{}\n", &self.prefix, l))).unwrap(); } stdout.flush()?; - self.drawn_lines = self.lines.len(); Ok(()) } }