diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2024-01-06 22:05:37 -0800 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2024-01-06 22:05:37 -0800 |
| commit | bb5480126fb4417339000f183b0d6787c7cb2b82 (patch) | |
| tree | a87ca6672d061b8f340b0ac40fee7f22f806b62e /src/term.rs | |
| parent | Fix some bugs with long lines. (diff) | |
| download | editor-bb5480126fb4417339000f183b0d6787c7cb2b82.tar.zst | |
Use a b-tree for the rope.
Now it's balanced :D
Diffstat (limited to 'src/term.rs')
| -rw-r--r-- | src/term.rs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/term.rs b/src/term.rs index 8f44b23..9c7e2cc 100644 --- a/src/term.rs +++ b/src/term.rs @@ -1,13 +1,16 @@ use libc::{termios, winsize}; use std::error::Error; -use std::io::{Read, Stdin}; +use std::io::{stdin, stdout, Read, Write}; pub fn size() -> Result<winsize, Box<dyn Error>> { unsafe { let mut window: winsize = std::mem::zeroed(); let status = libc::ioctl(1, libc::TIOCGWINSZ, &mut window); if status < 0 { - return Err(Box::from(format!("terminal size: ioctl failed with code {}", status))); + return Err(Box::from(format!( + "terminal size: ioctl failed with code {}", + status + ))); } return Ok(window); } @@ -48,11 +51,15 @@ pub struct RawHandle { impl Drop for RawHandle { fn drop(&mut self) { + let _ = write!(stdout(), "\x1b[?7h"); + let _ = stdout().flush(); let _ = set_attr(&self.old); } } pub fn raw() -> Result<RawHandle, Box<dyn Error>> { + write!(stdout(), "\x1b[?7l")?; + stdout().flush()?; let old = get_attr()?; set_attr(&make_raw())?; return Ok(RawHandle { old: old }); @@ -69,7 +76,7 @@ pub enum Key { Char(u8), } -pub fn read_key(stdin: &mut Stdin) -> Result<Key, Box<dyn Error>> { +pub fn read_key() -> Result<Key, Box<dyn Error>> { const CTRL_Q: u8 = 17; const CTRL_S: u8 = 19; const BACKSPACE: u8 = 127; @@ -77,7 +84,7 @@ pub fn read_key(stdin: &mut Stdin) -> Result<Key, Box<dyn Error>> { loop { let mut buf = vec![0; 1]; - stdin.read_exact(&mut buf)?; + stdin().read_exact(&mut buf)?; if buf[0] == CTRL_Q { return Ok(Key::CtrlQ); } @@ -92,7 +99,7 @@ pub fn read_key(stdin: &mut Stdin) -> Result<Key, Box<dyn Error>> { } // Try to handle an escape sequence. let mut buf = vec![0; 2]; - stdin.read_exact(&mut buf)?; + stdin().read_exact(&mut buf)?; if buf[0] != b'[' { // Unknown escape sequence, just read another key. continue; |
