parse-tree
Jordan Orelli 2 years ago
parent d1c379c755
commit f8f59c2de5

@ -1,8 +1,10 @@
mod error; mod error;
mod line; mod line;
mod log; mod log;
mod prompt;
use line::Line; use line::Line;
use prompt::Prompt;
use windows::Win32::{Foundation::HANDLE, System::Console}; use windows::Win32::{Foundation::HANDLE, System::Console};
use anyhow::{Context, Result}; use anyhow::{Context, Result};
@ -250,7 +252,9 @@ fn main() -> Result<()> {
let stdout = stdout_handle()?; let stdout = stdout_handle()?;
let mut buf = [Console::INPUT_RECORD::default(); 100]; let mut buf = [Console::INPUT_RECORD::default(); 100];
let mut line = Line::new(); let mut line = Line::new();
let prompt = Prompt::new();
prompt.print()?;
loop { loop {
let mut n: u32 = 0; let mut n: u32 = 0;
unsafe { unsafe {
@ -313,13 +317,15 @@ fn main() -> Result<()> {
None, None,
None, None,
))?; ))?;
prompt.print()?;
line.clear(); line.clear();
} }
} else if key_code == 74 } else if key_code == 74
&& (modifiers & Console::LEFT_CTRL_PRESSED && (modifiers & Console::LEFT_CTRL_PRESSED
== Console::LEFT_CTRL_PRESSED) == Console::LEFT_CTRL_PRESSED)
{ {
let text = "•"; // red bullet
let text = "\x1b[31m\u{2022}\x1b[0m";
Error::check(Console::WriteConsoleA( Error::check(Console::WriteConsoleA(
stdout, stdout,
text.as_bytes(), text.as_bytes(),

@ -0,0 +1,27 @@
use crate::{error::Error, stdout_handle};
use anyhow::Result;
use windows::Win32::System::Console;
pub struct Prompt {
s: String,
}
impl Prompt {
pub fn new() -> Self {
Self {
s: String::from("\x1b[32m>\x1b[0m "),
}
}
pub fn print(&self) -> Result<()> {
unsafe {
Error::check(Console::WriteConsoleA(
stdout_handle()?,
self.s.as_bytes(),
None,
None,
))?;
}
Ok(())
}
}
Loading…
Cancel
Save