增加颜色常量

This commit is contained in:
pointer-to-bios 2024-02-04 02:55:56 +08:00
parent 4eec22a71e
commit 2b2dc2d5bc
3 changed files with 30 additions and 18 deletions

View File

@ -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));

View File

@ -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) {

View File

@ -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<Color> for u32 {
fn from(value: Color) -> Self {
let res = (value.0 as u32) << 16 | (value.1 as u32) << 8 | (value.2 as u32);