ctrl-l clears the screen

parse-tree
Jordan Orelli 2 years ago
parent ca94a86a24
commit 534df2b6ef

@ -25,6 +25,10 @@ impl Line {
s s
} }
pub fn show(&self) -> String {
self.chars.iter().collect()
}
pub fn back(&mut self) -> bool { pub fn back(&mut self) -> bool {
if self.cursor > 0 { if self.cursor > 0 {
self.cursor -= 1; self.cursor -= 1;

@ -274,10 +274,15 @@ fn main() -> Result<()> {
// debug!("----------------------------------------"); // debug!("----------------------------------------");
match input.next()? { match input.next()? {
input::Event::Key(event) => { input::Event::Key(event) => {
debug!("{}", event);
if event.down { if event.down {
if event.code.val == 0 {
debug!("{}", event);
} else {
warn!("{}", event);
}
continue; continue;
} }
info!("{}", event);
if event.code == key::ENTER { if event.code == key::ENTER {
newline(stdout)?; newline(stdout)?;
@ -316,7 +321,7 @@ fn main() -> Result<()> {
} }
if event.ctrl && event.code == key::D { if event.ctrl && event.code == key::D {
debug!("ctrl-d"); debug!("⎈ d: exit");
unsafe { unsafe {
CloseHandle(stdout); CloseHandle(stdout);
} }
@ -324,7 +329,7 @@ fn main() -> Result<()> {
} }
if event.ctrl && event.code == key::J { if event.ctrl && event.code == key::J {
debug!("ctrl-j"); debug!("⎈ j: dot");
unsafe { unsafe {
// red bullet // red bullet
let text = "\x1b[31m\u{2022}\x1b[0m"; let text = "\x1b[31m\u{2022}\x1b[0m";
@ -333,6 +338,19 @@ fn main() -> Result<()> {
continue; continue;
} }
if event.ctrl && event.code == key::L {
debug!("⎈ l: clear");
let text = "\x1b[2J\x1b[0;0H";
unsafe {
Error::check(Console::WriteConsoleA(stdout, text.as_bytes(), None, None))?;
}
prompt.print()?;
unsafe {
Error::check(Console::WriteConsoleA(stdout, line.show().as_bytes(), None, None))?;
}
continue;
}
// TODO: something better here, this is crappy. I should be checking characters // TODO: something better here, this is crappy. I should be checking characters
// based on their unicode categories, not this garbo // based on their unicode categories, not this garbo
if !event.char.is_control() { if !event.char.is_control() {

Loading…
Cancel
Save