diff --git a/src/debugger/print.rs b/src/debugger/print.rs index 8ee87ee..e7e42b2 100644 --- a/src/debugger/print.rs +++ b/src/debugger/print.rs @@ -10,7 +10,7 @@ pub struct Writer; impl io::Write for Writer { fn write(&mut self, buf: &[u8]) -> io::Result { // TODO: Make this good - print(String::from_utf8_lossy(buf).to_string()); + print(String::from_utf8_lossy(buf).to_string(), true); Ok(buf.len()) } @@ -34,11 +34,14 @@ pub(super) mod is_minimal { } } -pub fn write(f: &mut impl io::Write, string: String) -> Result<(), io::Error> { +pub fn write(f: &mut impl io::Write, string: String, minimal: bool) -> Result<(), io::Error> { if !is_minimal::get() { write!(f, "{}", ColoredString::from(string).blue())?; return Ok(()); } + if !minimal { + return Ok(()); + } let mut chars = string.chars(); while let Some(ch) = chars.next() { @@ -52,32 +55,44 @@ pub fn write(f: &mut impl io::Write, string: String) -> Result<(), io::Error> { Ok(()) } -pub fn print(string: String) { +pub fn print(string: String, minimal: bool) { let is_line_start = string.chars().next_back() == Some('\n'); - write(&mut io::stderr(), string).expect("write to stderr should not fail"); + write(&mut io::stderr(), string, minimal).expect("write to stderr should not fail"); terminal_line_start::set(is_line_start); } #[macro_export] macro_rules! dwrite { + (% $f:expr, $fmt:literal $($tt:tt)* ) => {{ + crate::debugger::_write($f, format!($fmt $($tt)*), false) + }}; ( $f:expr, $fmt:literal $($tt:tt)* ) => {{ - crate::debugger::_write($f, format!($fmt $($tt)*)) + crate::debugger::_write($f, format!($fmt $($tt)*), true) }}; } #[macro_export] macro_rules! dprint { + (% $fmt:literal $($tt:tt)* ) => {{ + crate::debugger::_print(format!($fmt $($tt)*), false); + }}; ( $fmt:literal $($tt:tt)* ) => {{ - crate::debugger::_print(format!($fmt $($tt)*)); + crate::debugger::_print(format!($fmt $($tt)*), true); }}; } #[macro_export] macro_rules! dprintln { + (%) => {{ + crate::debugger::_print("\n".to_string(), false); + }}; + (% $fmt:literal $($tt:tt)* ) => {{ + crate::debugger::_print(format!(concat!($fmt, "\n") $($tt)*), false); + }}; () => {{ - crate::debugger::_print("\n".to_string()); + crate::debugger::_print("\n".to_string(), true); }}; ( $fmt:literal $($tt:tt)* ) => {{ - crate::debugger::_print(format!(concat!($fmt, "\n") $($tt)*)); + crate::debugger::_print(format!(concat!($fmt, "\n") $($tt)*), true); }}; } diff --git a/src/debugger/source.rs b/src/debugger/source.rs index 5602eab..81fe898 100644 --- a/src/debugger/source.rs +++ b/src/debugger/source.rs @@ -80,8 +80,8 @@ impl SourceReader for SourceMode { }; // Echo prompt and command for non-terminal source // Equivalent code found in terminal source - dprint!("\x1b[1mCommand: "); - dprintln!("{}", command.unwrap_or("\x1b[3m(end of input)").trim()); + dprint!(%"\x1b[1mCommand: "); + dprintln!(%"{}", command.unwrap_or("\x1b[3m(end of input)").trim()); command } } @@ -251,7 +251,7 @@ impl Terminal { // Print prompt and current input // Equivalent code found in non-terminal source - dwrite!(&mut self.term, "\x1b[1mCommand: \x1b[0m").unwrap(); + dwrite!(% &mut self.term, "\x1b[1mCommand: \x1b[0m").unwrap(); // Inline `self.get_current()` due to borrowing issues let current = if self.is_next() { diff --git a/src/runtime.rs b/src/runtime.rs index 9d04c00..593c6b2 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -140,10 +140,10 @@ impl RunEnvironment { loop { if let Some(debugger) = &mut self.debugger { if !terminal_line_start::get() { - dprintln!(); + dprintln!(%); } - dprintln!(); - dprintln!("Program counter at: 0x{:04x}", self.state.pc); + dprintln!(%); + dprintln!(%"Program counter at: 0x{:04x}", self.state.pc); match debugger.wait_for_action(&mut self.state) { Action::Proceed => (), Action::StopDebugger => {