small software-rendered rust tty
layers
bendn 9 months ago
parent 3229b9a · commit 1211e34
-rw-r--r--src/main.rs57
-rw-r--r--src/term.rs5
-rw-r--r--x20
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),
diff --git a/x b/x
index 5aa0c72..543ad87 100644
--- a/x
+++ b/x
@@ -1 +1,19 @@
-]0;os@klunk:~/pattypan[?2004h[os@klunk pattypan]$ ab� \ No newline at end of file
+]0;os@klunk:~/pattypan[?2004h[os@klunk pattypan]$ trans :zh hi
+[?2004l hi
+/hī/
+
+你好
+(Nǐ hǎo)
+
+Definitions of hi
+[ English -> 简体中文 ]
+
+interjection
+ 嗨!
+ Hi!, Hey!, Alas!, Oh!
+ 你好!
+ Hello!, Hi!, Hallo!
+
+hi
+ 你好, 嗨
+]0;os@klunk:~/pattypan[?2004h[os@klunk pattypan]$ \ No newline at end of file