Beautiful lines
This commit is contained in:
parent
093845a4c6
commit
2e771773b6
53
src/lib.rs
53
src/lib.rs
|
@ -170,37 +170,48 @@ impl<W: Write> Multiview<W> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Restarts the selected tile.
|
/// Restarts the selected tile.
|
||||||
pub fn restart(&mut self) -> io::Result<()> {
|
pub fn restart(&mut self) {
|
||||||
let tile = self.tile_mut(self.selected);
|
let tile = self.tile_mut(self.selected);
|
||||||
tile.restart()
|
tile.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Restarts all tiles.
|
/// Restarts all tiles.
|
||||||
pub fn restart_all(&mut self) -> io::Result<()> {
|
pub fn restart_all(&mut self) {
|
||||||
for row in &mut self.tiles {
|
for row in &mut self.tiles {
|
||||||
for tile in row {
|
for tile in row {
|
||||||
tile.restart()?;
|
tile.restart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Kills the selected tile.
|
/// Kills the selected tile.
|
||||||
pub fn kill(&mut self) -> io::Result<()> {
|
pub fn kill(&mut self) {
|
||||||
let tile = self.tile_mut(self.selected);
|
let tile = self.tile_mut(self.selected);
|
||||||
tile.kill()
|
tile.kill();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Kills all tiles.
|
/// Kills all tiles.
|
||||||
pub fn kill_all(&mut self) -> io::Result<()> {
|
pub fn kill_all(&mut self) {
|
||||||
for row in &mut self.tiles {
|
for row in &mut self.tiles {
|
||||||
for tile in row {
|
for tile in row {
|
||||||
tile.kill()?;
|
tile.kill();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
/// Adds a line to the current tile.
|
||||||
|
pub fn add_line(&mut self) {
|
||||||
|
let tile = self.tile_mut(self.selected);
|
||||||
|
tile.add_line();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Adds a line to every tile.
|
||||||
|
pub fn add_line_all(&mut self) {
|
||||||
|
for row in &mut self.tiles {
|
||||||
|
for tile in row {
|
||||||
|
tile.add_line();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Exits.
|
/// Exits.
|
||||||
|
@ -209,7 +220,7 @@ impl<W: Write> Multiview<W> {
|
||||||
|
|
||||||
for row in &mut self.tiles {
|
for row in &mut self.tiles {
|
||||||
for tile in row {
|
for tile in row {
|
||||||
tile.kill().ok();
|
tile.kill()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -222,14 +233,16 @@ impl<W: Write> Multiview<W> {
|
||||||
Msg::Stdout(coords, line) => self.push_stdout(coords, line),
|
Msg::Stdout(coords, line) => self.push_stdout(coords, line),
|
||||||
Msg::Stderr(coords, line) => self.push_stderr(coords, line),
|
Msg::Stderr(coords, line) => self.push_stderr(coords, line),
|
||||||
Msg::Click(x, y) => self.select_tile((x, y), self.term_size),
|
Msg::Click(x, y) => self.select_tile((x, y), self.term_size),
|
||||||
Msg::Restart => self.restart()?,
|
Msg::Restart => self.restart(),
|
||||||
Msg::RestartAll => self.restart_all()?,
|
Msg::RestartAll => self.restart_all(),
|
||||||
Msg::Kill => self.kill()?,
|
Msg::Kill => self.kill(),
|
||||||
Msg::KillAll => self.kill_all()?,
|
Msg::KillAll => self.kill_all(),
|
||||||
Msg::ScrollDown(step) => self.scroll_down(step),
|
Msg::ScrollDown(step) => self.scroll_down(step),
|
||||||
Msg::ScrollUp(step) => self.scroll_up(step),
|
Msg::ScrollUp(step) => self.scroll_up(step),
|
||||||
Msg::ScrollFullDown => self.scroll_full_down(),
|
Msg::ScrollFullDown => self.scroll_full_down(),
|
||||||
Msg::ScrollFullUp => self.scroll_full_up(),
|
Msg::ScrollFullUp => self.scroll_full_up(),
|
||||||
|
Msg::AddLine => self.add_line(),
|
||||||
|
Msg::AddLineAll => self.add_line_all(),
|
||||||
Msg::Exit => self.exit(),
|
Msg::Exit => self.exit(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,6 +292,12 @@ pub enum Msg {
|
||||||
/// Scroll to the bottom of the log.
|
/// Scroll to the bottom of the log.
|
||||||
ScrollFullDown,
|
ScrollFullDown,
|
||||||
|
|
||||||
|
/// Adds a line to the current tile.
|
||||||
|
AddLine,
|
||||||
|
|
||||||
|
/// Adds a line to every tile.
|
||||||
|
AddLineAll,
|
||||||
|
|
||||||
/// The program was asked to exit.
|
/// The program was asked to exit.
|
||||||
Exit,
|
Exit,
|
||||||
}
|
}
|
||||||
|
@ -349,6 +368,8 @@ pub fn main() -> io::Result<()> {
|
||||||
Event::Key(Key::Char('R')) => sender.send(Msg::RestartAll).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::Kill).unwrap(),
|
||||||
Event::Key(Key::Char('K')) => sender.send(Msg::KillAll).unwrap(),
|
Event::Key(Key::Char('K')) => sender.send(Msg::KillAll).unwrap(),
|
||||||
|
Event::Key(Key::Char('l')) => sender.send(Msg::AddLine).unwrap(),
|
||||||
|
Event::Key(Key::Char('L')) => sender.send(Msg::AddLineAll).unwrap(),
|
||||||
Event::Key(Key::Down) => sender.send(Msg::ScrollDown(1)).unwrap(),
|
Event::Key(Key::Down) => sender.send(Msg::ScrollDown(1)).unwrap(),
|
||||||
Event::Key(Key::Up) => sender.send(Msg::ScrollUp(1)).unwrap(),
|
Event::Key(Key::Up) => sender.send(Msg::ScrollUp(1)).unwrap(),
|
||||||
Event::Key(Key::End) => sender.send(Msg::ScrollFullDown).unwrap(),
|
Event::Key(Key::End) => sender.send(Msg::ScrollFullDown).unwrap(),
|
||||||
|
|
39
src/tile.rs
39
src/tile.rs
|
@ -1,6 +1,6 @@
|
||||||
//! This module contains everything related to tiles.
|
//! This module contains everything related to tiles.
|
||||||
|
|
||||||
use std::io::{self, Read};
|
use std::io::Read;
|
||||||
use std::process::Stdio;
|
use std::process::Stdio;
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
@ -239,7 +239,19 @@ impl Tile {
|
||||||
}
|
}
|
||||||
|
|
||||||
sender
|
sender
|
||||||
.send(Msg::Stdout(coords, format!("\n{}\n", line)))
|
.send(Msg::Stdout(
|
||||||
|
coords,
|
||||||
|
format!(
|
||||||
|
"\n{}{}{}\n",
|
||||||
|
if code == Some(0) {
|
||||||
|
color::Green.fg_str()
|
||||||
|
} else {
|
||||||
|
color::Red.fg_str()
|
||||||
|
},
|
||||||
|
line,
|
||||||
|
color::Reset.fg_str()
|
||||||
|
),
|
||||||
|
))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -611,15 +623,28 @@ impl Tile {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Kill the child command.
|
/// Kill the child command.
|
||||||
pub fn kill(&mut self) -> io::Result<()> {
|
pub fn kill(&mut self) {
|
||||||
self.pty = None;
|
self.pty = None;
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Restarts the child command.
|
/// Restarts the child command.
|
||||||
pub fn restart(&mut self) -> io::Result<()> {
|
pub fn restart(&mut self) {
|
||||||
self.kill()?;
|
self.kill();
|
||||||
self.start();
|
self.start();
|
||||||
Ok(())
|
}
|
||||||
|
|
||||||
|
/// Draws a line.
|
||||||
|
pub fn add_line(&mut self) {
|
||||||
|
let mut line = String::new();
|
||||||
|
for _ in 0..self.inner_size.0 - 1 {
|
||||||
|
line.push('─');
|
||||||
|
}
|
||||||
|
|
||||||
|
self.sender
|
||||||
|
.send(Msg::Stdout(
|
||||||
|
self.coords,
|
||||||
|
format!("\n{}{}\n", color::Reset.fg_str(), line),
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue