small software-rendered rust tty
| -rw-r--r-- | src/main.rs | 12 | ||||
| -rw-r--r-- | src/render.rs | 5 | ||||
| -rw-r--r-- | src/term.rs | 11 |
3 files changed, 17 insertions, 11 deletions
diff --git a/src/main.rs b/src/main.rs index ef9c4ac..22f6c6f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,9 +36,6 @@ fn spawn(shell: &str) -> Result<OwnedFd> { ForkptyResult::Child => { let sh = Command::new(shell).env("TERM", "xterm").spawn()?.wait(); - // std::thread::sleep(Duration::from_millis(5000)); - // exit(0); - exit(0); } ForkptyResult::Parent { child, master } => { @@ -105,11 +102,15 @@ fn main() -> Result<()> { std::thread::spawn(move || { use Key::*; let mut shifting = false; + let mut ctrl = false; while let Ok((k, s)) = krx.recv() { if !s { if k == LeftShift || k == RightShift { shifting = false; } + if k == LeftCtrl || k == RightCtrl { + ctrl = false; + } continue; } @@ -119,6 +120,10 @@ fn main() -> Result<()> { shifting = true; continue; } + LeftCtrl | RightCtrl => { + ctrl = true; + continue; + } Enter => &b"\n"[..], Escape => b"\x1b", Up => b"\x1b[A", @@ -156,6 +161,7 @@ fn main() -> Result<()> { Key0 | Key1 | Key2 | Key3 | Key4 | Key5 | Key6 | Key7 | Key8 | Key9 => &[k as u8 + b'0'], + _ if ctrl => &[k as u8 - 9], _ if shifting => &[k as u8 - 10 + b'A'], _ => &[k as u8 - 10 + b'a'], }; diff --git a/src/render.rs b/src/render.rs index 2f82dbc..6ab9dc5 100644 --- a/src/render.rs +++ b/src/render.rs @@ -22,7 +22,10 @@ pub fn render( .zip(0..) .skip(1) { - for (cell, j) in col.iter().skip(2).zip(0..) { + for (&(mut cell), j) in col.iter().skip(2).zip(0..) { + if cell.style.flags & crate::term::INVERT != 0 { + std::mem::swap(&mut cell.style.bg, &mut cell.style.color); + } if cell.style.bg != colors::BACKGROUND { let cell = Image::<_, 4>::build( sz.ceil() as u32, diff --git a/src/term.rs b/src/term.rs index 3ece3c1..f3d9453 100644 --- a/src/term.rs +++ b/src/term.rs @@ -156,13 +156,9 @@ impl Terminal { ModeSet(2) => self.style.flags |= DIM, ModeSet(3) => self.style.flags |= ITALIC, ModeSet(4) => self.style.flags |= UNDERLINE, - ModeSet(7) => std::mem::swap( - &mut self.style.bg, - &mut self.style.color, - ), + ModeSet(7) => self.style.flags |= INVERT, ModeSet(9) => self.style.flags |= STRIKETHROUGH, ModeSet(22) => self.style.flags &= !(BOLD | DIM), - _ => {} } } @@ -371,8 +367,9 @@ enum StyleAction { pub const BOLD: u8 = 1; pub const DIM: u8 = 1 << 1; pub const ITALIC: u8 = 1 << 2; -pub const UNDERLINE: u8 = 1 << 3; -pub const STRIKETHROUGH: u8 = 1 << 4; +pub const INVERT: u8 = 1 << 3; +pub const UNDERLINE: u8 = 1 << 4; +pub const STRIKETHROUGH: u8 = 1 << 5; fn value<'a>( r: impl std::ops::RangeBounds<u16>, |