Skip to content

Commit

Permalink
refactor(console): extract Console::write
Browse files Browse the repository at this point in the history
  • Loading branch information
mkroening committed Dec 12, 2024
1 parent 226515b commit b2405ef
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,27 @@ use crate::arch;

pub(crate) struct Console(());

impl Console {
pub fn write(&mut self, buf: &[u8]) {
arch::output_message_buf(buf);
}
}

/// A collection of methods that are required to format
/// a message to Hermit's console.
impl fmt::Write for Console {
/// Print a string of characters.
#[inline]
fn write_str(&mut self, s: &str) -> fmt::Result {
if !s.is_empty() {
let buf = s.as_bytes();
arch::output_message_buf(buf);
self.write(s.as_bytes());
}

Ok(())
}
}

static CONSOLE: InterruptTicketMutex<Console> = InterruptTicketMutex::new(Console(()));
pub(crate) static CONSOLE: InterruptTicketMutex<Console> = InterruptTicketMutex::new(Console(()));

#[doc(hidden)]
pub fn _print(args: fmt::Arguments<'_>) {
Expand Down

0 comments on commit b2405ef

Please sign in to comment.