Unverified Commit c0e8767d authored by jschwe's avatar jschwe Committed by GitHub
Browse files

Add UTF-8 support to Console (#69)

- Swap order of write_char and write_str to match order of trait
- Implement write_char by calling write_str to match the implementation in the standard library
- Add output_message_buf for printing of a buffer.
- Convert str to UTF-8 encoded byte buffer before printing.
parent de7766c9
......@@ -70,5 +70,5 @@ pub use crate::arch::x86_64::kernel::{
};
#[cfg(target_arch = "x86_64")]
pub use crate::arch::x86_64::kernel::{
get_processor_count, message_output_init, output_message_byte,
get_processor_count, message_output_init, output_message_buf, output_message_byte,
};
......@@ -277,6 +277,13 @@ pub fn output_message_byte(byte: u8) {
}
}
//#[cfg(not(test))]
pub fn output_message_buf(buf: &[u8]) {
for byte in buf {
output_message_byte(*byte);
}
}
/// Real Boot Processor initialization as soon as we have put the first Welcome message on the screen.
#[cfg(not(test))]
pub fn boot_processor_init() {
......
......@@ -15,19 +15,20 @@ pub struct Console;
/// A collection of methods that are required to format
/// a message to HermitCore's console.
impl fmt::Write for Console {
/// Print a single character.
fn write_char(&mut self, c: char) -> fmt::Result {
arch::output_message_byte(c as u8);
Ok(())
}
/// Print a string of characters.
fn write_str(&mut self, s: &str) -> fmt::Result {
for character in s.chars() {
self.write_char(character).unwrap();
if s.len() > 0 {
let buf = s.as_bytes();
arch::output_message_buf(buf);
}
Ok(())
}
/// Print a single character.
fn write_char(&mut self, c: char) -> fmt::Result {
self.write_str(c.encode_utf8(&mut [0; 4]))
}
}
pub static CONSOLE: SpinlockIrqSave<Console> = SpinlockIrqSave::new(Console);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment