From bc536132adfaa0962bddc332eb504cf890e4bd4c Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sat, 4 Mar 2023 22:26:21 -0600 Subject: [PATCH] do something other than echo --- src/line.rs | 18 +++--------------- src/main.rs | 15 +++++++++++---- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/line.rs b/src/line.rs index 21eeba2..34f3359 100644 --- a/src/line.rs +++ b/src/line.rs @@ -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, @@ -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 { diff --git a/src/main.rs b/src/main.rs index decbcdb..f3ad436 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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,