ctrl-l clears the screen

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

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

@ -274,10 +274,15 @@ fn main() -> Result<()> {
// debug!("----------------------------------------");
match input.next()? {
input::Event::Key(event) => {
debug!("{}", event);
if event.down {
if event.code.val == 0 {
debug!("{}", event);
} else {
warn!("{}", event);
}
continue;
}
info!("{}", event);
if event.code == key::ENTER {
newline(stdout)?;
@ -316,7 +321,7 @@ fn main() -> Result<()> {
}
if event.ctrl && event.code == key::D {
debug!("ctrl-d");
debug!("⎈ d: exit");
unsafe {
CloseHandle(stdout);
}
@ -324,7 +329,7 @@ fn main() -> Result<()> {
}
if event.ctrl && event.code == key::J {
debug!("ctrl-j");
debug!("⎈ j: dot");
unsafe {
// red bullet
let text = "\x1b[31m\u{2022}\x1b[0m";
@ -333,6 +338,19 @@ fn main() -> Result<()> {
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
// based on their unicode categories, not this garbo
if !event.char.is_control() {

Loading…
Cancel
Save