hmm how do you debug a shell

parse-tree
Jordan Orelli 2 years ago
parent 1f46fe5bb7
commit 05c3d0832c

16
Cargo.lock generated

@ -8,6 +8,21 @@ version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800" checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "log"
version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
dependencies = [
"cfg-if",
]
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.51" version = "1.0.51"
@ -68,6 +83,7 @@ name = "wash"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"log",
"thiserror", "thiserror",
"windows", "windows",
] ]

@ -9,6 +9,8 @@ edition = "2021"
anyhow = "1.0" anyhow = "1.0"
thiserror = "1.0" thiserror = "1.0"
log = "0.4"
[dependencies.windows] [dependencies.windows]
version = "0.44.0" version = "0.44.0"
features = [ features = [

@ -0,0 +1,19 @@
pub use log::{debug, error, info, set_logger, set_max_level, trace, warn, LevelFilter};
use log::{Metadata, Record};
pub struct Log;
impl log::Log for Log {
fn enabled(&self, _metadata: &Metadata) -> bool {
true
}
fn log(&self, record: &Record) {
if self.enabled(record.metadata()) {
println!("{} - {}", record.level(), record.args());
}
}
fn flush(&self) {}
}

@ -1,11 +1,11 @@
mod error; mod error;
mod log;
use std::io::{self, Write};
use windows::Win32::{Foundation::HANDLE, System::Console}; use windows::Win32::{Foundation::HANDLE, System::Console};
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use crate::error::Error; use crate::{error::Error, log::*};
fn print_input_mode(mode: Console::CONSOLE_MODE) { fn print_input_mode(mode: Console::CONSOLE_MODE) {
// Characters read by the ReadFile or ReadConsole function are written to the active screen // Characters read by the ReadFile or ReadConsole function are written to the active screen
@ -197,8 +197,6 @@ fn setup_stdin() -> Result<()> {
unsafe { unsafe {
let handle = stdin_handle()?; let handle = stdin_handle()?;
Error::check(Console::GetConsoleMode(handle, &mut mode))?; Error::check(Console::GetConsoleMode(handle, &mut mode))?;
println!("Stdin details:");
print_input_mode(mode);
// allow terminal input characters // allow terminal input characters
mode |= Console::ENABLE_VIRTUAL_TERMINAL_INPUT; mode |= Console::ENABLE_VIRTUAL_TERMINAL_INPUT;
@ -216,6 +214,9 @@ fn setup_stdin() -> Result<()> {
mode |= Console::ENABLE_MOUSE_INPUT; mode |= Console::ENABLE_MOUSE_INPUT;
Error::check(Console::SetConsoleMode(handle, mode))?; Error::check(Console::SetConsoleMode(handle, mode))?;
Error::check(Console::GetConsoleMode(handle, &mut mode))?;
println!("Stdin details:");
print_input_mode(mode);
} }
Ok(()) Ok(())
} }
@ -235,6 +236,7 @@ fn setup_stdout() -> Result<()> {
} }
fn main() -> Result<()> { fn main() -> Result<()> {
_ = set_logger(&Log {}).map(|()| set_max_level(LevelFilter::Info));
setup_stdin()?; setup_stdin()?;
setup_stdout()?; setup_stdout()?;
@ -243,7 +245,7 @@ fn main() -> Result<()> {
loop { loop {
let mut n: u32 = 0; let mut n: u32 = 0;
unsafe { unsafe {
Error::check(Console::ReadConsoleInputA(stdin, &mut buf, &mut n))?; Error::check(Console::ReadConsoleInputW(stdin, &mut buf, &mut n))?;
} }
let n = n as usize; let n = n as usize;
println!("read: {:?}", n); println!("read: {:?}", n);

Loading…
Cancel
Save