small software-rendered rust tty
layers
| -rw-r--r-- | src/main.rs | 57 | ||||
| -rw-r--r-- | src/term.rs | 5 | ||||
| -rw-r--r-- | x | 20 |
3 files changed, 56 insertions, 26 deletions
diff --git a/src/main.rs b/src/main.rs index 8ad18e5..5a110f0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,13 +55,11 @@ fn write(fd: BorrowedFd, x: &[u8]) -> Result<()> { Ok(()) } -struct KeyPress(mpsc::Sender<Key>); +struct KeyPress(mpsc::Sender<(Key, bool)>); impl InputCallback for KeyPress { fn add_char(&mut self, _: u32) {} fn set_key_state(&mut self, key: Key, state: bool) { - if state { - self.0.send(key).unwrap(); - } + self.0.send((key, state)).unwrap(); } } enum Event { @@ -82,7 +80,7 @@ fn main() -> Result<()> { )?; // input - let (ktx, krx) = mpsc::channel::<Key>(); + let (ktx, krx) = mpsc::channel(); w.set_input_callback(Box::new(KeyPress(ktx))); w.update(); @@ -92,24 +90,37 @@ fn main() -> Result<()> { std::thread::spawn(move || { use Key::*; - while let Ok(k) = krx.recv() { - let x = match k { - Enter => b"\n", - Space => b" ", - Period => b".", - Slash => b"/", - Backslash => b"\\", - Backspace => b"", - LeftBracket => b"[", - RightBracket => b"]", - Comma => b",", - - Key0 | Key1 | Key2 | Key3 | Key4 | Key5 | Key6 | Key7 - | Key8 | Key9 => &[k as u8 + b'0'], - - _ => &[k as u8 - 10 + b'a'], - }; - write(pty1.as_fd(), x).unwrap(); + let mut shifting = false; + while let Ok((k, s)) = krx.recv() { + if s == true { + if k == LeftShift || k == RightShift { + shifting = true; + continue; + } + let x = match k { + Enter => b"\n", + Space => b" ", + Period => b".", + Slash => b"/", + Backslash => b"\\", + Backspace => b"", + LeftBracket => b"[", + RightBracket => b"]", + Semicolon if shifting => b":", + Semicolon => b";", + Comma => b",", + + Key0 | Key1 | Key2 | Key3 | Key4 | Key5 | Key6 + | Key7 | Key8 | Key9 => &[k as u8 + b'0'], + + _ => &[k as u8 - 10 + b'a'], + }; + write(pty1.as_fd(), x).unwrap(); + } else { + if k == LeftShift || k == RightShift { + shifting = false; + } + } } }); diff --git a/src/term.rs b/src/term.rs index e2831f0..87192bd 100644 --- a/src/term.rs +++ b/src/term.rs @@ -75,8 +75,9 @@ impl Terminal { x.params .iter() .map(|x| match x { - ctlfun::Parameter::Default => 0, - ctlfun::Parameter::Value(x) => *x, + ctlfun::Parameter::Default => + "default".to_string(), + ctlfun::Parameter::Value(x) => x.to_string(), }) .collect::<Vec<_>>(), String::from_utf8_lossy(&x.bytes), @@ -1 +1,19 @@ -]0;os@klunk:~/pattypan[?2004h[os@klunk pattypan]$ ab[K[K�
\ No newline at end of file +]0;os@klunk:~/pattypan[?2004h[os@klunk pattypan]$ trans :zh hi
+[?2004l
hi
+/hī/
+
+[1m你好[22m
+[1m(Nǐ hǎo)[22m
+
+Definitions of [4mhi[24m
+[ [4mEnglish[24m -> [1m简体中文[22m ]
+
+interjection
+[1m 嗨![22m
+ Hi!, Hey!, Alas!, Oh!
+[1m 你好![22m
+ Hello!, Hi!, Hallo!
+
+[4mhi[24m
+ [1m你好[22m, [1m嗨[22m
+]0;os@klunk:~/pattypan[?2004h[os@klunk pattypan]$
\ No newline at end of file |