aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/main.rs b/src/main.rs
index 0cc9ad4..3663052 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -21,7 +21,7 @@ fn line_offset(stdin: &mut Reader, line: &Rope, col: u16) -> Result<usize, Box<d
return Ok(i);
}
let c = line.byte(i);
- if c > 127 {
+ if !(c == b'\t' || b' ' <= c && c <= b'~') {
break;
}
if n == col {
@@ -231,12 +231,12 @@ impl State {
}
fn keypress(&mut self, key: Key) -> Result<bool, Box<dyn Error>> {
- const CTRL_Q: char = (b'Q' - b'@') as char;
- const CTRL_S: char = (b'S' - b'@') as char;
- const CTRL_Y: char = (b'Y' - b'@') as char;
- const CTRL_Z: char = (b'Z' - b'@') as char;
- const BACKSPACE: char = (b'H' - b'@') as char;
- const OTHER_BACKSPACE: char = '\x7f';
+ const CTRL_Q: char = (b'Q' ^ b'@') as char;
+ const CTRL_S: char = (b'S' ^ b'@') as char;
+ const CTRL_Y: char = (b'Y' ^ b'@') as char;
+ const CTRL_Z: char = (b'Z' ^ b'@') as char;
+ const BACKSPACE: char = (b'H' ^ b'@') as char;
+ const OTHER_BACKSPACE: char = (b'?' ^ b'@') as char;
let inserting = self.inserting;
self.inserting = false;
@@ -448,7 +448,7 @@ impl State {
}
Key::Char(CTRL_S) => {
let mut f = File::create(&self.path)?;
- self.buf.print(&mut f)?;
+ self.buf.write(&mut f)?;
f.sync_all()?;
}
Key::Char(CTRL_Z) => {
@@ -546,15 +546,15 @@ impl State {
.line_start(self.row_start + usize::from(self.cursor_row))
+ self.line_offset;
let mut buf = [0; 4];
- let s = c.encode_utf8(&mut buf);
+ let r = Rope::new(c.encode_utf8(&mut buf));
self.buf = self
.buf
.slice(0, offset)
- .concat(&Rope::new(s))
+ .concat(&r)
.concat(&self.buf.slice(offset, self.buf.len()));
- self.line_offset += s.len();
+ self.line_offset += r.len();
self.need_repaint_line = true;
- stdout().write_all(s.as_bytes())?;
+ r.print(&mut stdout())?;
stdout().flush()?;
}
}