diff --git a/src/kernel/klog.rs b/src/kernel/klog.rs index 8cc5416..756d84d 100644 --- a/src/kernel/klog.rs +++ b/src/kernel/klog.rs @@ -41,7 +41,7 @@ impl KernelLogger { pub fn fatal(&mut self, msg: Message) { let msg = MessageBuilder::new() .message("Fatal: ") - .foreground_color(Color(0xee, 0xa, 0xa)) + .foreground_color(Color::RED) .append(MessageBuilder::from_message(msg)) .build(); self.fatal_queue.push((SystemTime::now(), msg)); @@ -50,7 +50,7 @@ impl KernelLogger { pub fn error(&mut self, msg: Message) { let msg = MessageBuilder::new() .message("Error: ") - .foreground_color(Color(0xaa, 0x22, 0x22)) + .foreground_color(Color::ORANGE) .append(MessageBuilder::from_message(msg)) .build(); self.error_queue.push((SystemTime::now(), msg)); @@ -59,7 +59,7 @@ impl KernelLogger { pub fn warning(&mut self, msg: Message) { let msg = MessageBuilder::new() .message("Warning: ") - .foreground_color(Color(0xaa, 0xa, 0xaa)) + .foreground_color(Color::PURPLE) .append(MessageBuilder::from_message(msg)) .build(); self.warning_queue.push((SystemTime::now(), msg)); @@ -68,7 +68,7 @@ impl KernelLogger { pub fn info(&mut self, msg: Message) { let msg = MessageBuilder::new() .message("Info: ") - .foreground_color(Color(0xa, 0xee, 0xa)) + .foreground_color(Color::GREEN) .append(MessageBuilder::from_message(msg)) .build(); self.info_queue.push((SystemTime::now(), msg)); @@ -77,7 +77,7 @@ impl KernelLogger { pub fn debug(&mut self, msg: Message) { let msg = MessageBuilder::new() .message("Debug: ") - .foreground_color(Color(0xee, 0xee, 0xee)) + .foreground_color(Color::WHITE) .append(MessageBuilder::from_message(msg)) .build(); self.debug_queue.push((SystemTime::now(), msg)); @@ -86,7 +86,7 @@ impl KernelLogger { pub fn trace(&mut self, msg: Message) { let msg = MessageBuilder::new() .message("Trace: ") - .foreground_color(Color(0xee, 0xee, 0xee)) + .foreground_color(Color::WHITE) .append(MessageBuilder::from_message(msg)) .build(); self.trace_queue.push((SystemTime::now(), msg)); diff --git a/src/kernel/main.rs b/src/kernel/main.rs index aa74b88..d50d8b1 100644 --- a/src/kernel/main.rs +++ b/src/kernel/main.rs @@ -13,7 +13,7 @@ extern "C" fn kmain_rust() -> ! { logger.info(message!( Msg("Hello, "), Msg("Metaverse"), - FgColor(Color(0xa, 0xee, 0xa)), + FgColor(Color::GREEN), Msg("!\n") )); for msg in logger.iter(LoggerLevel::Info) { diff --git a/src/kernel/tty/tty.rs b/src/kernel/tty/tty.rs index 38922ee..50b1470 100644 --- a/src/kernel/tty/tty.rs +++ b/src/kernel/tty/tty.rs @@ -7,21 +7,21 @@ use alloc::{ }; extern "C" { - fn tty_new(tty_type: u8, mode: u8) -> *mut u8; - fn tty_get(id: usize) -> *mut *mut u8; - fn tty_text_print(ttyx: *mut u8, string: *mut u8, color: u32, bgcolor: u32); - fn tty_get_id(tty: *mut u8) -> usize; + pub fn tty_new(tty_type: u8, mode: u8) -> *mut u8; + pub fn tty_get(id: usize) -> *mut *mut u8; + pub fn tty_text_print(ttyx: *mut u8, string: *mut u8, color: u32, bgcolor: u32); + pub fn tty_get_id(tty: *mut u8) -> usize; - fn tty_get_width(tty: *mut u8) -> usize; - fn tty_get_height(tty: *mut u8) -> usize; + pub fn tty_get_width(tty: *mut u8) -> usize; + pub fn tty_get_height(tty: *mut u8) -> usize; - fn tty_get_type(tty: *mut u8) -> u8; - fn tty_get_mode(tty: *mut u8) -> u8; + pub fn tty_get_type(tty: *mut u8) -> u8; + pub fn tty_get_mode(tty: *mut u8) -> u8; - fn tty_is_enabled(tty: *mut u8) -> bool; + pub fn tty_is_enabled(tty: *mut u8) -> bool; - fn tty_enable(tty: *mut u8) -> bool; - fn tty_disable(tty: *mut u8); + pub fn tty_enable(tty: *mut u8) -> bool; + pub fn tty_disable(tty: *mut u8); } pub enum Type { @@ -144,6 +144,18 @@ impl Tty { #[derive(Clone, Copy)] pub struct Color(pub u8, pub u8, pub u8); +impl Color { + pub const WHITE: Color = Color(0xee, 0xee, 0xee); + pub const BLACK: Color = Color(0, 0, 0); + pub const RED: Color = Color(0xee, 0x22, 0x22); + pub const GREEN: Color = Color(0x22, 0xee, 0x22); + pub const BLUE: Color = Color(0x22, 0x22, 0xee); + pub const YELLOW: Color = Color(0xee, 0x22, 0x22); + pub const ORANGE: Color = Color(0xee, 0xee, 0x22); + pub const PURPLE: Color = Color(0xee, 0, 0xee); + pub const PINK: Color = Color(0xee, 0x44, 0x66); +} + impl From for u32 { fn from(value: Color) -> Self { let res = (value.0 as u32) << 16 | (value.1 as u32) << 8 | (value.2 as u32);