alright things are getting dark now

parse-tree
Jordan Orelli 2 years ago
parent 15e3ca93cc
commit 592ebf6e3a

@ -160,6 +160,19 @@ impl Reader {
Ok(rec.into()) Ok(rec.into())
} }
fn log_recs(&mut self) {
debug!(" +---------------------+");
for i in 0..self.buf_len {
let rec = self.buf[i as usize];
let e: Event = rec.into();
match e {
Event::Key(k) => debug!(" | {} |", k),
_ => debug!(" | {:<14?} |", &e),
}
}
debug!(" +---------------------+");
}
fn next_rec(&mut self) -> Result<Console::INPUT_RECORD> { fn next_rec(&mut self) -> Result<Console::INPUT_RECORD> {
if self.buf_idx as u32 >= self.buf_len { if self.buf_idx as u32 >= self.buf_len {
unsafe { unsafe {
@ -170,6 +183,7 @@ impl Reader {
))?; ))?;
} }
debug!("• {}", self.buf_len); debug!("• {}", self.buf_len);
self.log_recs();
self.buf_idx = 0; self.buf_idx = 0;
} }
@ -179,33 +193,90 @@ impl Reader {
} }
fn next_escape_sequence(&mut self) -> Result<Event> { fn next_escape_sequence(&mut self) -> Result<Event> {
self.take_bracket()?;
match self.next_escape_char()? { match self.next_escape_char()? {
'[' => match self.next_escape_char()? {
'A' => Ok(Event::Up), 'A' => Ok(Event::Up),
'B' => Ok(Event::Down), 'B' => Ok(Event::Down),
'C' => Ok(Event::Right), 'C' => Ok(Event::Right),
'D' => Ok(Event::Left), 'D' => Ok(Event::Left),
'H' => Ok(Event::Home), 'H' => Ok(Event::Home),
'F' => Ok(Event::End), 'F' => Ok(Event::End),
e => Err(Error::input_error(format!("unexpected escape char: {}", e)).into()), '1' => match self.next_escape_char()? {
'3' => match self.next_escape_char()? {
';' => match self.next_escape_char()? {
'5' => match self.next_escape_char()? {
'u' => Ok(Event::Drop(String::from("13;5u"))),
e => Err(Error::input_error(format!("[13;5 unexpected escape char: {}", e)).into()),
} }
e => Err(Error::input_error(format!("[13; unexpected escape char: {}", e)).into()),
} }
e => Err(Error::input_error(format!("[13 unexpected escape char: {}", e)).into()),
fn take_bracket(&mut self) -> Result<()> {
let rec = self.next_rec()?;
if rec.EventType as u32 != Console::KEY_EVENT {
Err(Error::input_error("failed to read escape sequence: not a key event").into())
} else {
unsafe {
let event = rec.Event.KeyEvent;
if event.wVirtualKeyCode == 0 && event.uChar.UnicodeChar == 91 {
Ok(())
} else {
Err(Error::input_error("failed to read escape sequence: not a [").into())
} }
'5' => match self.next_escape_char()? {
'~' => Ok(Event::Drop(String::from("[15~ - F5"))),
e => Err(Error::input_error(format!("[15 unexpected escape char: {}", e)).into()),
} }
'7' => match self.next_escape_char()? {
'~' => Ok(Event::Drop(String::from("[17~ - F6"))),
e => Err(Error::input_error(format!("[17 unexpected escape char: {}", e)).into()),
} }
'8' => match self.next_escape_char()? {
'~' => Ok(Event::Drop(String::from("[18~ - F7"))),
e => Err(Error::input_error(format!("[18 unexpected escape char: {}", e)).into()),
} }
'9' => match self.next_escape_char()? {
'~' => Ok(Event::Drop(String::from("[19~ - F8"))),
e => Err(Error::input_error(format!("[19 unexpected escape char: {}", e)).into()),
}
e => Err(Error::input_error(format!("[1 unexpected escape char: {}", e)).into()),
},
'2' => match self.next_escape_char()? {
'0' => match self.next_escape_char()? {
'~' => Ok(Event::Drop(String::from("[20~ - F9"))),
e => Err(Error::input_error(format!("[20 unexpected escape char: {}", e)).into()),
}
'1' => match self.next_escape_char()? {
'~' => Ok(Event::Drop(String::from("[21~ - F10"))),
e => Err(Error::input_error(format!("[20 unexpected escape char: {}", e)).into()),
}
'3' => match self.next_escape_char()? {
'~' => Ok(Event::Drop(String::from("[23~ - F11"))),
e => Err(Error::input_error(format!("[23 unexpected escape char: {}", e)).into()),
}
'4' => match self.next_escape_char()? {
'~' => Ok(Event::Drop(String::from("[24~ - F12"))),
e => Err(Error::input_error(format!("[24 unexpected escape char: {}", e)).into()),
}
e => Err(Error::input_error(format!("[2 unexpected escape char: {}", e)).into()),
}
e => Err(Error::input_error(format!("[ unexpected escape char: {}", e)).into()),
},
'O' => match self.next_escape_char()? {
'P' => Ok(Event::Drop(String::from("OP - F1"))),
'Q' => Ok(Event::Drop(String::from("OQ - F2"))),
'R' => Ok(Event::Drop(String::from("OR - F3"))),
'S' => Ok(Event::Drop(String::from("OS - F4"))),
e => Err(Error::input_error(format!("O unexpected escape char: {}", e)).into()),
}
e => Err(Error::input_error(format!("unexpected escape char: {}", e)).into()),
}
}
// fn take_bracket(&mut self) -> Result<()> {
// let rec = self.next_rec()?;
// if rec.EventType as u32 != Console::KEY_EVENT {
// Err(Error::input_error("failed to read escape sequence: not a key event").into())
// } else {
// unsafe {
// let event = rec.Event.KeyEvent;
// if event.wVirtualKeyCode == 0 && event.uChar.UnicodeChar == 91 {
// Ok(())
// } else {
// Err(Error::input_error("failed to read escape sequence: not a [").into())
// }
// }
// }
// }
fn next_escape_char(&mut self) -> Result<char> { fn next_escape_char(&mut self) -> Result<char> {
let rec = self.next_rec()?; let rec = self.next_rec()?;
@ -240,6 +311,7 @@ pub enum Event {
Down, Down,
Home, Home,
End, End,
Drop(String),
} }
const ALT_KEYS: u32 = 0x0002 | 0x0001; const ALT_KEYS: u32 = 0x0002 | 0x0001;

@ -43,7 +43,8 @@ impl fmt::Display for Event {
let ctrl = if self.ctrl { '⎈' } else { '·' }; let ctrl = if self.ctrl { '⎈' } else { '·' };
let alt = if self.alt { '⎇' } else { '·' }; let alt = if self.alt { '⎇' } else { '·' };
let shift = if self.shift { '⇧'} else { '·' }; let shift = if self.shift { '⇧'} else { '·' };
write!(f, "{} {} {} {} {: >3} {}", down, ctrl, alt, shift, self.code.val, sym) let c = if self.char.is_control() { '·' } else { self.char };
write!(f, "{} {} {} {} {: >3} {} {: >1} {: >3}", down, ctrl, alt, shift, self.code.val, sym, c, self.char as u16)
} }
} }

@ -16,7 +16,7 @@ use crate::log::*;
use shell::Shell; use shell::Shell;
fn main() -> Result<()> { fn main() -> Result<()> {
match Log::file("C:\\Users\\JordanOrelli\\wash.log") { match Log::file("C:\\Users\\jordan\\wash.log") {
Ok(f) => { Ok(f) => {
let target = Box::leak(Box::new(f)); let target = Box::leak(Box::new(f));
_ = set_logger(target).map(|()| set_max_level(LevelFilter::Debug)); _ = set_logger(target).map(|()| set_max_level(LevelFilter::Debug));
@ -183,19 +183,16 @@ fn main() -> Result<()> {
warn!("‽ {}", event); warn!("‽ {}", event);
} }
input::Event::Left => { shell.back(1)? } input::Event::Left => shell.back(1)?,
input::Event::Right => { shell.forward(1)? } input::Event::Right => shell.forward(1)?,
input::Event::Up => { input::Event::Up => debug!("⛬ ↑"),
debug!("⛬ ↑"); input::Event::Down => debug!("⛬ ↓"),
} input::Event::Home => shell.seek_left()?,
input::Event::Down => { input::Event::End => shell.seek_right()?,
debug!("⛬ ↓");
}
input::Event::Home => { shell.seek_left()? }
input::Event::End => { shell.seek_right()? }
input::Event::Focus(true) => {} input::Event::Focus(true) => {}
input::Event::Focus(false) => {} input::Event::Focus(false) => {}
input::Event::Menu(_command_id) => {} input::Event::Menu(_command_id) => {}
input::Event::Drop(seq) => debug!("? {}", seq),
input::Event::Mouse { .. } => {} input::Event::Mouse { .. } => {}
input::Event::Size => {} input::Event::Size => {}
} }

@ -144,8 +144,10 @@ impl Writer {
} }
pub fn back(&mut self, n: usize) -> Result<()> { pub fn back(&mut self, n: usize) -> Result<()> {
if n > 0 {
let text = format!("\x1b[{}D", n); let text = format!("\x1b[{}D", n);
self.write(text.as_bytes())?; self.write(text.as_bytes())?;
}
Ok(()) Ok(())
} }
@ -159,6 +161,11 @@ impl Writer {
self.write(b"\x1b[2J\x1b[0;0H")?; self.write(b"\x1b[2J\x1b[0;0H")?;
Ok(()) Ok(())
} }
pub fn hide_cursor(&mut self) -> Result<()> {
self.write(b"\x1b[?25l")?;
Ok(())
}
} }
impl Write for Writer { impl Write for Writer {

@ -9,14 +9,19 @@ pub struct Prompt {
impl Prompt { impl Prompt {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
s: String::from("\x1b[32m>\x1b[0m "), // +---------------------------- hide cursor
// | +------------------- start color
// | | +-------- clear styles
// | | | +- show cursor
// v v v v
s: String::from("\x1b[?25l\x1b[32m ▷ \x1b[0m\x1b[?25h"),
} }
} }
pub fn print(&self, output: &mut output::Writer) -> Result<()> { pub fn print(&self, output: &mut output::Writer) -> Result<()> {
match std::env::current_dir() { match std::env::current_dir() {
Ok(d) => { Ok(d) => {
let text = d.to_str().unwrap().to_owned() + " " + &self.s; let text = d.to_str().unwrap().to_owned() + &self.s;
output.write(text.as_bytes())?; output.write(text.as_bytes())?;
} }
Err(_) => { Err(_) => {

@ -175,3 +175,5 @@ impl Shell {
} }
} }
} }
// pub fn expand() { }

Loading…
Cancel
Save