增加内核日志功能 #3
|
@ -41,7 +41,7 @@ impl KernelLogger {
|
||||||
pub fn fatal(&mut self, msg: Message) {
|
pub fn fatal(&mut self, msg: Message) {
|
||||||
let msg = MessageBuilder::new()
|
let msg = MessageBuilder::new()
|
||||||
.message("Fatal: ")
|
.message("Fatal: ")
|
||||||
.foreground_color(Color(0xee, 0xa, 0xa))
|
.foreground_color(Color::RED)
|
||||||
.append(MessageBuilder::from_message(msg))
|
.append(MessageBuilder::from_message(msg))
|
||||||
.build();
|
.build();
|
||||||
self.fatal_queue.push((SystemTime::now(), msg));
|
self.fatal_queue.push((SystemTime::now(), msg));
|
||||||
|
@ -50,7 +50,7 @@ impl KernelLogger {
|
||||||
pub fn error(&mut self, msg: Message) {
|
pub fn error(&mut self, msg: Message) {
|
||||||
let msg = MessageBuilder::new()
|
let msg = MessageBuilder::new()
|
||||||
.message("Error: ")
|
.message("Error: ")
|
||||||
.foreground_color(Color(0xaa, 0x22, 0x22))
|
.foreground_color(Color::ORANGE)
|
||||||
.append(MessageBuilder::from_message(msg))
|
.append(MessageBuilder::from_message(msg))
|
||||||
.build();
|
.build();
|
||||||
self.error_queue.push((SystemTime::now(), msg));
|
self.error_queue.push((SystemTime::now(), msg));
|
||||||
|
@ -59,7 +59,7 @@ impl KernelLogger {
|
||||||
pub fn warning(&mut self, msg: Message) {
|
pub fn warning(&mut self, msg: Message) {
|
||||||
let msg = MessageBuilder::new()
|
let msg = MessageBuilder::new()
|
||||||
.message("Warning: ")
|
.message("Warning: ")
|
||||||
.foreground_color(Color(0xaa, 0xa, 0xaa))
|
.foreground_color(Color::PURPLE)
|
||||||
.append(MessageBuilder::from_message(msg))
|
.append(MessageBuilder::from_message(msg))
|
||||||
.build();
|
.build();
|
||||||
self.warning_queue.push((SystemTime::now(), msg));
|
self.warning_queue.push((SystemTime::now(), msg));
|
||||||
|
@ -68,7 +68,7 @@ impl KernelLogger {
|
||||||
pub fn info(&mut self, msg: Message) {
|
pub fn info(&mut self, msg: Message) {
|
||||||
let msg = MessageBuilder::new()
|
let msg = MessageBuilder::new()
|
||||||
.message("Info: ")
|
.message("Info: ")
|
||||||
.foreground_color(Color(0xa, 0xee, 0xa))
|
.foreground_color(Color::GREEN)
|
||||||
.append(MessageBuilder::from_message(msg))
|
.append(MessageBuilder::from_message(msg))
|
||||||
.build();
|
.build();
|
||||||
self.info_queue.push((SystemTime::now(), msg));
|
self.info_queue.push((SystemTime::now(), msg));
|
||||||
|
@ -77,7 +77,7 @@ impl KernelLogger {
|
||||||
pub fn debug(&mut self, msg: Message) {
|
pub fn debug(&mut self, msg: Message) {
|
||||||
let msg = MessageBuilder::new()
|
let msg = MessageBuilder::new()
|
||||||
.message("Debug: ")
|
.message("Debug: ")
|
||||||
.foreground_color(Color(0xee, 0xee, 0xee))
|
.foreground_color(Color::WHITE)
|
||||||
.append(MessageBuilder::from_message(msg))
|
.append(MessageBuilder::from_message(msg))
|
||||||
.build();
|
.build();
|
||||||
self.debug_queue.push((SystemTime::now(), msg));
|
self.debug_queue.push((SystemTime::now(), msg));
|
||||||
|
@ -86,7 +86,7 @@ impl KernelLogger {
|
||||||
pub fn trace(&mut self, msg: Message) {
|
pub fn trace(&mut self, msg: Message) {
|
||||||
let msg = MessageBuilder::new()
|
let msg = MessageBuilder::new()
|
||||||
.message("Trace: ")
|
.message("Trace: ")
|
||||||
.foreground_color(Color(0xee, 0xee, 0xee))
|
.foreground_color(Color::WHITE)
|
||||||
.append(MessageBuilder::from_message(msg))
|
.append(MessageBuilder::from_message(msg))
|
||||||
.build();
|
.build();
|
||||||
self.trace_queue.push((SystemTime::now(), msg));
|
self.trace_queue.push((SystemTime::now(), msg));
|
||||||
|
|
|
@ -13,7 +13,7 @@ extern "C" fn kmain_rust() -> ! {
|
||||||
logger.info(message!(
|
logger.info(message!(
|
||||||
Msg("Hello, "),
|
Msg("Hello, "),
|
||||||
Msg("Metaverse"),
|
Msg("Metaverse"),
|
||||||
FgColor(Color(0xa, 0xee, 0xa)),
|
FgColor(Color::GREEN),
|
||||||
Msg("!\n")
|
Msg("!\n")
|
||||||
));
|
));
|
||||||
for msg in logger.iter(LoggerLevel::Info) {
|
for msg in logger.iter(LoggerLevel::Info) {
|
||||||
|
|
|
@ -7,21 +7,21 @@ use alloc::{
|
||||||
};
|
};
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
fn tty_new(tty_type: u8, mode: u8) -> *mut u8;
|
pub fn tty_new(tty_type: u8, mode: u8) -> *mut u8;
|
||||||
fn tty_get(id: usize) -> *mut *mut u8;
|
pub fn tty_get(id: usize) -> *mut *mut u8;
|
||||||
fn tty_text_print(ttyx: *mut u8, string: *mut u8, color: u32, bgcolor: u32);
|
pub 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_get_id(tty: *mut u8) -> usize;
|
||||||
|
|
||||||
fn tty_get_width(tty: *mut u8) -> usize;
|
pub fn tty_get_width(tty: *mut u8) -> usize;
|
||||||
fn tty_get_height(tty: *mut u8) -> usize;
|
pub fn tty_get_height(tty: *mut u8) -> usize;
|
||||||
|
|
||||||
fn tty_get_type(tty: *mut u8) -> u8;
|
pub fn tty_get_type(tty: *mut u8) -> u8;
|
||||||
fn tty_get_mode(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;
|
pub fn tty_enable(tty: *mut u8) -> bool;
|
||||||
fn tty_disable(tty: *mut u8);
|
pub fn tty_disable(tty: *mut u8);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Type {
|
pub enum Type {
|
||||||
|
@ -144,6 +144,18 @@ impl Tty {
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub struct Color(pub u8, pub u8, pub u8);
|
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<Color> for u32 {
|
impl From<Color> for u32 {
|
||||||
fn from(value: Color) -> Self {
|
fn from(value: Color) -> Self {
|
||||||
let res = (value.0 as u32) << 16 | (value.1 as u32) << 8 | (value.2 as u32);
|
let res = (value.0 as u32) << 16 | (value.1 as u32) << 8 | (value.2 as u32);
|
||||||
|
|
Loading…
Reference in New Issue