From 534df2b6ef957692b6ccc5eb79d65da5e89571ec Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sun, 5 Mar 2023 07:07:16 -0600 Subject: [PATCH] ctrl-l clears the screen --- src/line.rs | 4 ++++ src/main.rs | 24 +++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/line.rs b/src/line.rs index 34f3359..3e0aa96 100644 --- a/src/line.rs +++ b/src/line.rs @@ -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; diff --git a/src/main.rs b/src/main.rs index 9bbda57..6f8fa1a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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() {