|
|
|
@ -14,6 +14,7 @@ use std::io::Write;
|
|
|
|
|
use anyhow::Result;
|
|
|
|
|
|
|
|
|
|
use crate::log::*;
|
|
|
|
|
use shell::Shell;
|
|
|
|
|
|
|
|
|
|
fn main() -> Result<()> {
|
|
|
|
|
match Log::file("C:\\Users\\JordanOrelli\\wash.log") {
|
|
|
|
@ -30,6 +31,7 @@ fn main() -> Result<()> {
|
|
|
|
|
let prompt = Prompt::new();
|
|
|
|
|
let mut input = input::Reader::new()?;
|
|
|
|
|
let mut output = output::Writer::new()?;
|
|
|
|
|
let shell = Shell::new();
|
|
|
|
|
|
|
|
|
|
prompt.print(&mut output)?;
|
|
|
|
|
info!("» enter");
|
|
|
|
@ -58,7 +60,7 @@ fn main() -> Result<()> {
|
|
|
|
|
vec![]
|
|
|
|
|
};
|
|
|
|
|
debug!("◇ {} {}", cmd.clone(), args.join(" "));
|
|
|
|
|
match shell::eval(&mut output, cmd.clone(), args.clone()) {
|
|
|
|
|
match shell.eval(&mut output, cmd.clone(), args.clone()) {
|
|
|
|
|
Ok(true) => info!("▷ {} {}", cmd, args.join(" ")),
|
|
|
|
|
Ok(false) => warn!("▷ {} {}", cmd, args.join(" ")),
|
|
|
|
|
Err(e) => {
|
|
|
|
@ -78,8 +80,7 @@ fn main() -> Result<()> {
|
|
|
|
|
if event.code == key::BACKSPACE {
|
|
|
|
|
if line.backspace() {
|
|
|
|
|
// move cursor back two spaces
|
|
|
|
|
output.write(b"\x1b[2D")?;
|
|
|
|
|
// output.back(2)?;
|
|
|
|
|
output.back(2)?;
|
|
|
|
|
let tail = format!("{} ", line.tail());
|
|
|
|
|
let n = tail.chars().count();
|
|
|
|
|
output.write(tail.as_bytes())?;
|
|
|
|
@ -87,8 +88,9 @@ fn main() -> Result<()> {
|
|
|
|
|
// after writing out the tail, rewind by the number of characters in
|
|
|
|
|
// the tail
|
|
|
|
|
if n > 1 {
|
|
|
|
|
let text = format!("\x1b[{}D", n - 1);
|
|
|
|
|
output.write(text.as_bytes())?;
|
|
|
|
|
// let text = format!("\x1b[{}D", n - 1);
|
|
|
|
|
output.back(n-1)?;
|
|
|
|
|
// output.write(text.as_bytes())?;
|
|
|
|
|
} else {
|
|
|
|
|
// honestly I can't remember how I figured this out
|
|
|
|
|
output.write(b" \x1b[1D")?;
|
|
|
|
@ -115,7 +117,7 @@ fn main() -> Result<()> {
|
|
|
|
|
// CTRL-L to clear the screen
|
|
|
|
|
if event.ctrl && event.code == key::L {
|
|
|
|
|
info!("» clear");
|
|
|
|
|
output.write(b"\x1b[2J\x1b[0;0H")?;
|
|
|
|
|
output.clear()?;
|
|
|
|
|
prompt.print(&mut output)?;
|
|
|
|
|
output.write(line.show().as_bytes())?;
|
|
|
|
|
continue;
|
|
|
|
@ -127,15 +129,13 @@ fn main() -> Result<()> {
|
|
|
|
|
let n = line.clear_left();
|
|
|
|
|
if n > 0 {
|
|
|
|
|
// move left by the number of elements removed
|
|
|
|
|
let text = format!("\x1b[{}D", n);
|
|
|
|
|
output.write(text.as_bytes())?;
|
|
|
|
|
output.back(n)?;
|
|
|
|
|
// draw the elements remaining, followed by a space for each removed
|
|
|
|
|
// element
|
|
|
|
|
let kept = line.show();
|
|
|
|
|
let text = format!("{}{:width$}", kept, "", width = n);
|
|
|
|
|
output.write(text.as_bytes())?;
|
|
|
|
|
let text = format!("\x1b[{}D", n + kept.chars().count());
|
|
|
|
|
output.write(text.as_bytes())?;
|
|
|
|
|
output.back(n + kept.chars().count())?;
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
@ -146,8 +146,7 @@ fn main() -> Result<()> {
|
|
|
|
|
let n = line.seek_left();
|
|
|
|
|
if n > 0 {
|
|
|
|
|
// move left by the distance seeked
|
|
|
|
|
let text = format!("\x1b[{}D", n);
|
|
|
|
|
output.write(text.as_bytes())?;
|
|
|
|
|
output.back(n)?;
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
@ -158,8 +157,7 @@ fn main() -> Result<()> {
|
|
|
|
|
let n = line.seek_right();
|
|
|
|
|
if n > 0 {
|
|
|
|
|
// move right by the distance seeked
|
|
|
|
|
let text = format!("\x1b[{}C", n);
|
|
|
|
|
output.write(text.as_bytes())?;
|
|
|
|
|
output.forward(n)?;
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
@ -177,8 +175,7 @@ fn main() -> Result<()> {
|
|
|
|
|
if n > 1 {
|
|
|
|
|
// if we wrote more than one character, because we weren't at the end, we
|
|
|
|
|
// need to rewind the terminal cursor to where it was.
|
|
|
|
|
let text = format!("\x1b[{}D", n - 1);
|
|
|
|
|
output.write(text.as_bytes())?;
|
|
|
|
|
output.back(n-1)?;
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
@ -188,13 +185,13 @@ fn main() -> Result<()> {
|
|
|
|
|
input::Event::Left => {
|
|
|
|
|
debug!("⛬ ←");
|
|
|
|
|
if line.back() {
|
|
|
|
|
output.write(b"\x1b[D")?; // lol this sucks
|
|
|
|
|
output.back(1)?;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
input::Event::Right => {
|
|
|
|
|
debug!("⛬ →");
|
|
|
|
|
if line.forward() {
|
|
|
|
|
output.write(b"\x1b[C")?; // lol this sucks
|
|
|
|
|
output.forward(1)?;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
input::Event::Up => {
|
|
|
|
|