Compare commits
2 Commits
4aca298ba5
...
7c77ce4179
Author | SHA1 | Date |
---|---|---|
Thomas Forgione | 7c77ce4179 | |
Thomas Forgione | 75f4e69949 |
27
src/lib.rs
27
src/lib.rs
|
@ -154,6 +154,23 @@ impl<W: Write> Multiview<W> {
|
||||||
Ok(())
|
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.
|
/// Exits.
|
||||||
pub fn exit(&mut self) {
|
pub fn exit(&mut self) {
|
||||||
write!(self.stdout, "{}", cursor::Show).ok();
|
write!(self.stdout, "{}", cursor::Show).ok();
|
||||||
|
@ -189,6 +206,12 @@ pub enum Msg {
|
||||||
/// Restarts all tiles.
|
/// Restarts all tiles.
|
||||||
RestartAll,
|
RestartAll,
|
||||||
|
|
||||||
|
/// Kills the selected tile.
|
||||||
|
Kill,
|
||||||
|
|
||||||
|
/// Kills all tiles.
|
||||||
|
KillAll,
|
||||||
|
|
||||||
/// Scroll up one line.
|
/// Scroll up one line.
|
||||||
ScrollUp,
|
ScrollUp,
|
||||||
|
|
||||||
|
@ -269,6 +292,8 @@ pub fn main() -> io::Result<()> {
|
||||||
Event::Key(Key::Char('q')) => sender.send(Msg::Exit).unwrap(),
|
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::Restart).unwrap(),
|
||||||
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::KillAll).unwrap(),
|
||||||
Event::Key(Key::Down) => sender.send(Msg::ScrollDown).unwrap(),
|
Event::Key(Key::Down) => sender.send(Msg::ScrollDown).unwrap(),
|
||||||
Event::Key(Key::Up) => sender.send(Msg::ScrollUp).unwrap(),
|
Event::Key(Key::Up) => sender.send(Msg::ScrollUp).unwrap(),
|
||||||
Event::Key(Key::End) => sender.send(Msg::ScrollFullDown).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::ScrollDown) => multiview.scroll_down(),
|
||||||
Ok(Msg::Restart) => multiview.restart()?,
|
Ok(Msg::Restart) => multiview.restart()?,
|
||||||
Ok(Msg::RestartAll) => multiview.restart_all()?,
|
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::ScrollUp) => multiview.scroll_up(),
|
||||||
Ok(Msg::ScrollFullDown) => multiview.scroll_full_down(),
|
Ok(Msg::ScrollFullDown) => multiview.scroll_full_down(),
|
||||||
Ok(Msg::ScrollFullUp) => multiview.scroll_full_up(),
|
Ok(Msg::ScrollFullUp) => multiview.scroll_full_up(),
|
||||||
|
|
22
src/tile.rs
22
src/tile.rs
|
@ -212,6 +212,15 @@ impl Tile {
|
||||||
);
|
);
|
||||||
|
|
||||||
sender.send(Msg::Stdout(coords, exit_string)).unwrap();
|
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 {
|
thread::spawn(move || loop {
|
||||||
|
@ -256,7 +265,6 @@ impl Tile {
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
// TODO fix utf8
|
|
||||||
self.stdout.last_mut().unwrap().push(c);
|
self.stdout.last_mut().unwrap().push(c);
|
||||||
|
|
||||||
if self.counting {
|
if self.counting {
|
||||||
|
@ -398,7 +406,6 @@ impl Tile {
|
||||||
|
|
||||||
match &subbuffer[0..3] {
|
match &subbuffer[0..3] {
|
||||||
"\x1b[K" => {
|
"\x1b[K" => {
|
||||||
if line_index >= scroll && line_index <= h + scroll {
|
|
||||||
if current_char_index < w {
|
if current_char_index < w {
|
||||||
let mut spaces = String::new();
|
let mut spaces = String::new();
|
||||||
for _ in current_char_index..w {
|
for _ in current_char_index..w {
|
||||||
|
@ -418,7 +425,6 @@ impl Tile {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
_ => buffer.push(subbuffer),
|
_ => buffer.push(subbuffer),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -430,8 +436,6 @@ impl Tile {
|
||||||
line_index += 1;
|
line_index += 1;
|
||||||
current_char_index = 0;
|
current_char_index = 0;
|
||||||
|
|
||||||
if line_index >= scroll && line_index <= h + scroll {
|
|
||||||
if max_char_index < w {
|
|
||||||
let mut spaces = format!(
|
let mut spaces = format!(
|
||||||
"{}",
|
"{}",
|
||||||
cursor::Goto(x + max_char_index, y + line_index as u16 - scroll)
|
cursor::Goto(x + max_char_index, y + line_index as u16 - scroll)
|
||||||
|
@ -440,7 +444,6 @@ impl Tile {
|
||||||
spaces.push(DELETE_CHAR);
|
spaces.push(DELETE_CHAR);
|
||||||
}
|
}
|
||||||
buffer.push(spaces);
|
buffer.push(spaces);
|
||||||
}
|
|
||||||
|
|
||||||
max_char_index = 0;
|
max_char_index = 0;
|
||||||
|
|
||||||
|
@ -451,11 +454,9 @@ impl Tile {
|
||||||
|
|
||||||
last_line_index = line_index;
|
last_line_index = line_index;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
'\r' => {
|
'\r' => {
|
||||||
current_char_index = 0;
|
current_char_index = 0;
|
||||||
if line_index >= scroll && line_index <= h + scroll {
|
|
||||||
buffer.push(format!(
|
buffer.push(format!(
|
||||||
"{}",
|
"{}",
|
||||||
cursor::Goto(x, y + line_index as u16 - scroll)
|
cursor::Goto(x, y + line_index as u16 - scroll)
|
||||||
|
@ -463,10 +464,8 @@ impl Tile {
|
||||||
|
|
||||||
last_line_index = line_index;
|
last_line_index = line_index;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
if line_index >= scroll && line_index <= h + scroll {
|
|
||||||
current_char_index += 1;
|
current_char_index += 1;
|
||||||
max_char_index = std::cmp::max(max_char_index, current_char_index);
|
max_char_index = std::cmp::max(max_char_index, current_char_index);
|
||||||
|
|
||||||
|
@ -475,7 +474,6 @@ impl Tile {
|
||||||
current_char_index = 1;
|
current_char_index = 1;
|
||||||
max_char_index = 1;
|
max_char_index = 1;
|
||||||
|
|
||||||
if line_index >= scroll && line_index <= h + scroll {
|
|
||||||
buffer.push(format!(
|
buffer.push(format!(
|
||||||
"{}",
|
"{}",
|
||||||
cursor::Goto(x, y + line_index as u16 - scroll)
|
cursor::Goto(x, y + line_index as u16 - scroll)
|
||||||
|
@ -483,13 +481,11 @@ impl Tile {
|
||||||
|
|
||||||
last_line_index = line_index;
|
last_line_index = line_index;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
buffer.push(format!("{}", c));
|
buffer.push(format!("{}", c));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let mut spaces = format!(
|
let mut spaces = format!(
|
||||||
"{}",
|
"{}",
|
||||||
|
|
Loading…
Reference in New Issue