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())
}
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> {
if self.buf_idx as u32 >= self.buf_len {
unsafe {
@ -170,6 +183,7 @@ impl Reader {
))?;
}
debug!("• {}", self.buf_len);
self.log_recs();
self.buf_idx = 0;
}
@ -179,34 +193,91 @@ impl Reader {
}
fn next_escape_sequence(&mut self) -> Result<Event> {
self.take_bracket()?;
match self.next_escape_char()? {
'A' => Ok(Event::Up),
'B' => Ok(Event::Down),
'C' => Ok(Event::Right),
'D' => Ok(Event::Left),
'H' => Ok(Event::Home),
'F' => Ok(Event::End),
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())
'[' => match self.next_escape_char()? {
'A' => Ok(Event::Up),
'B' => Ok(Event::Down),
'C' => Ok(Event::Right),
'D' => Ok(Event::Left),
'H' => Ok(Event::Home),
'F' => Ok(Event::End),
'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()),
}
'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> {
let rec = self.next_rec()?;
if rec.EventType as u32 != Console::KEY_EVENT {
@ -240,6 +311,7 @@ pub enum Event {
Down,
Home,
End,
Drop(String),
}
const ALT_KEYS: u32 = 0x0002 | 0x0001;

@ -43,7 +43,8 @@ impl fmt::Display for Event {
let ctrl = if self.ctrl { '⎈' } else { '·' };
let alt = if self.alt { '⎇' } 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;
fn main() -> Result<()> {
match Log::file("C:\\Users\\JordanOrelli\\wash.log") {
match Log::file("C:\\Users\\jordan\\wash.log") {
Ok(f) => {
let target = Box::leak(Box::new(f));
_ = set_logger(target).map(|()| set_max_level(LevelFilter::Debug));
@ -183,19 +183,16 @@ fn main() -> Result<()> {
warn!("‽ {}", event);
}
input::Event::Left => { shell.back(1)? }
input::Event::Right => { shell.forward(1)? }
input::Event::Up => {
debug!("⛬ ↑");
}
input::Event::Down => {
debug!("⛬ ↓");
}
input::Event::Home => { shell.seek_left()? }
input::Event::End => { shell.seek_right()? }
input::Event::Left => shell.back(1)?,
input::Event::Right => shell.forward(1)?,
input::Event::Up => debug!("⛬ ↑"),
input::Event::Down => debug!("⛬ ↓"),
input::Event::Home => shell.seek_left()?,
input::Event::End => shell.seek_right()?,
input::Event::Focus(true) => {}
input::Event::Focus(false) => {}
input::Event::Menu(_command_id) => {}
input::Event::Drop(seq) => debug!("? {}", seq),
input::Event::Mouse { .. } => {}
input::Event::Size => {}
}

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

@ -9,14 +9,19 @@ pub struct Prompt {
impl Prompt {
pub fn new() -> 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<()> {
match std::env::current_dir() {
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())?;
}
Err(_) => {

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

Loading…
Cancel
Save