From 75f4e69949b473c13b9331606f70e73efccbeec1 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Wed, 25 Oct 2023 21:16:52 +0200 Subject: [PATCH] Kill shortcut, line when killed --- src/lib.rs | 27 +++++++++++++++++++++++++++ src/tile.rs | 9 +++++++++ 2 files changed, 36 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index cb63822..272bf0c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -154,6 +154,23 @@ impl Multiview { Ok(()) } + /// Kills the selected tile. + pub fn kill(&mut self) -> io::Result<()> { + let tile = self.tile_mut(self.selected); + tile.kill() + } + + /// Kills all tiles. + pub fn kill_all(&mut self) -> io::Result<()> { + for row in &mut self.tiles { + for tile in row { + tile.kill()?; + } + } + + Ok(()) + } + /// Exits. pub fn exit(&mut self) { write!(self.stdout, "{}", cursor::Show).ok(); @@ -189,6 +206,12 @@ pub enum Msg { /// Restarts all tiles. RestartAll, + /// Kills the selected tile. + Kill, + + /// Kills all tiles. + KillAll, + /// Scroll up one line. ScrollUp, @@ -269,6 +292,8 @@ pub fn main() -> io::Result<()> { Event::Key(Key::Char('q')) => sender.send(Msg::Exit).unwrap(), Event::Key(Key::Char('r')) => sender.send(Msg::Restart).unwrap(), Event::Key(Key::Char('R')) => sender.send(Msg::RestartAll).unwrap(), + Event::Key(Key::Char('k')) => sender.send(Msg::Kill).unwrap(), + Event::Key(Key::Char('K')) => sender.send(Msg::KillAll).unwrap(), Event::Key(Key::Down) => sender.send(Msg::ScrollDown).unwrap(), Event::Key(Key::Up) => sender.send(Msg::ScrollUp).unwrap(), Event::Key(Key::End) => sender.send(Msg::ScrollFullDown).unwrap(), @@ -293,6 +318,8 @@ pub fn main() -> io::Result<()> { Ok(Msg::ScrollDown) => multiview.scroll_down(), Ok(Msg::Restart) => multiview.restart()?, Ok(Msg::RestartAll) => multiview.restart_all()?, + Ok(Msg::Kill) => multiview.kill()?, + Ok(Msg::KillAll) => multiview.kill_all()?, Ok(Msg::ScrollUp) => multiview.scroll_up(), Ok(Msg::ScrollFullDown) => multiview.scroll_full_down(), Ok(Msg::ScrollFullUp) => multiview.scroll_full_up(), diff --git a/src/tile.rs b/src/tile.rs index aa5ea41..2ca681e 100644 --- a/src/tile.rs +++ b/src/tile.rs @@ -212,6 +212,15 @@ impl Tile { ); sender.send(Msg::Stdout(coords, exit_string)).unwrap(); + + let mut line = String::new(); + for _ in 0..size.0 - 1 { + line.push('─'); + } + + sender + .send(Msg::Stdout(coords, format!("\n{}\n", line))) + .unwrap(); }); thread::spawn(move || loop {