do something other than echo

parse-tree
Jordan Orelli 2 years ago
parent 6c97ff2889
commit bc536132ad

@ -1,8 +1,3 @@
use crate::{error::Error, stdout_handle};
use anyhow::Result;
use windows::Win32::System::Console;
pub struct Line {
/// the current contents of the line
chars: Vec<char>,
@ -24,17 +19,10 @@ impl Line {
self.chars.clear();
}
pub fn print(&self) -> Result<()> {
pub fn pop(&mut self) -> String {
let s: String = self.chars.iter().collect();
unsafe {
Error::check(Console::WriteConsoleA(
stdout_handle()?,
s.as_bytes(),
None,
None,
))?;
}
Ok(())
self.clear();
s
}
pub fn back(&mut self) -> bool {

@ -141,6 +141,16 @@ fn newline(stdout: HANDLE) -> Result<()> {
Ok(())
}
fn eval(line: String) -> Result<()> {
if line == "pwd" {
let pb = std::env::current_dir()?;
println!("{}", pb.as_path().as_os_str().to_str().unwrap());
return Ok(());
}
println!("{}", line);
Ok(())
}
fn main() -> Result<()> {
match Log::file("C:\\Users\\JordanOrelli\\wash.log") {
Ok(f) => {
@ -169,10 +179,8 @@ fn main() -> Result<()> {
if event.code == key::ENTER {
newline(stdout)?;
line.print()?;
newline(stdout)?;
eval(line.pop())?;
prompt.print()?;
line.clear();
continue;
}
@ -187,7 +195,6 @@ fn main() -> Result<()> {
Error::check(Console::WriteConsoleA(stdout, text.as_bytes(), None, None))?;
}
let tail = format!("{} ", line.tail());
let n = tail.chars().count();
unsafe {
Error::check(Console::WriteConsoleA(
stdout,

Loading…
Cancel
Save