ok ctrl+c works

parse-tree
Jordan Orelli 2 years ago
parent b548b908e7
commit b8e001f008

@ -27,6 +27,7 @@ impl<W> Log<W>
where where
W: io::Write, W: io::Write,
{ {
#[allow(dead_code)]
pub fn from_writer(w: W) -> Self { pub fn from_writer(w: W) -> Self {
Self { Self {
out: Arc::new(Mutex::new(w)), out: Arc::new(Mutex::new(w)),

@ -5,7 +5,10 @@ mod prompt;
use line::Line; use line::Line;
use prompt::Prompt; use prompt::Prompt;
use windows::Win32::{Foundation::HANDLE, System::Console}; use windows::Win32::{
Foundation::{CloseHandle, HANDLE},
System::Console,
};
use anyhow::{Context, Result}; use anyhow::{Context, Result};
@ -199,6 +202,8 @@ pub fn stdout_handle() -> Result<HANDLE> {
fn setup_stdin() -> Result<()> { fn setup_stdin() -> Result<()> {
let mut mode = Console::CONSOLE_MODE(0); let mut mode = Console::CONSOLE_MODE(0);
unsafe { unsafe {
Console::SetConsoleCP(65001);
let handle = stdin_handle()?; let handle = stdin_handle()?;
Error::check(Console::GetConsoleMode(handle, &mut mode))?; Error::check(Console::GetConsoleMode(handle, &mut mode))?;
@ -329,6 +334,13 @@ fn main() -> Result<()> {
prompt.print()?; prompt.print()?;
line.clear(); line.clear();
} }
} else if key_code == 67
&& (modifiers & Console::LEFT_CTRL_PRESSED
== Console::LEFT_CTRL_PRESSED)
{
// this is CTRL+C
CloseHandle(stdout);
return Ok(());
} else if key_code == 74 } else if key_code == 74
&& (modifiers & Console::LEFT_CTRL_PRESSED && (modifiers & Console::LEFT_CTRL_PRESSED
== Console::LEFT_CTRL_PRESSED) == Console::LEFT_CTRL_PRESSED)

Loading…
Cancel
Save