mirror of
https://github.com/XunilGroup/XunilOS.git
synced 2026-04-25 11:49:03 +02:00
Use white instead of black for serial console text, add print macros
This commit is contained in:
@@ -2,9 +2,22 @@ use crate::driver::graphics::framebuffer::{with_framebuffer, Framebuffer};
|
||||
use crate::driver::graphics::font_render::render_text;
|
||||
use crate::driver::graphics::base::rgb;
|
||||
use spin::Mutex;
|
||||
use core::fmt::{self, Write};
|
||||
|
||||
const DEFAULT_FONT_SIZE: usize = 3;
|
||||
|
||||
pub struct ConsoleWriter<'a> {
|
||||
pub fb: &'a mut Framebuffer,
|
||||
pub console: &'a mut SerialConsole,
|
||||
}
|
||||
|
||||
impl Write for ConsoleWriter<'_> {
|
||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||
self.console.render_text(self.fb, s);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SerialConsole {
|
||||
start_x: usize,
|
||||
current_y: usize
|
||||
@@ -19,8 +32,8 @@ impl SerialConsole {
|
||||
}
|
||||
|
||||
pub fn render_text(&mut self, fb: &mut Framebuffer, text: &str) {
|
||||
self.current_y = render_text(fb, self.start_x - ((text.len() - text.matches('\n').count()) * DEFAULT_FONT_SIZE * 4), self.current_y, text, DEFAULT_FONT_SIZE, rgb(0, 0, 0));
|
||||
self.current_y = render_text(fb, self.start_x - ((text.len() - text.matches('\n').count()) * DEFAULT_FONT_SIZE * 4), self.current_y, "\n", DEFAULT_FONT_SIZE, rgb(0, 0, 0)); // add a newline
|
||||
self.current_y = render_text(fb, self.start_x - ((text.len() - text.matches('\n').count()) * DEFAULT_FONT_SIZE * 4), self.current_y, text, DEFAULT_FONT_SIZE, rgb(255, 255, 255));
|
||||
self.current_y = render_text(fb, self.start_x - ((text.len() - text.matches('\n').count()) * DEFAULT_FONT_SIZE * 4), self.current_y, "\n", DEFAULT_FONT_SIZE, rgb(255, 255, 255)); // add a newline
|
||||
}
|
||||
|
||||
pub fn clear(&mut self, start_y: usize) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#![no_main]
|
||||
|
||||
use core::arch::asm;
|
||||
use core::fmt::Write;
|
||||
|
||||
use limine::BaseRevision;
|
||||
use limine::request::{FramebufferRequest, RequestsEndMarker, RequestsStartMarker};
|
||||
@@ -10,7 +11,7 @@ pub mod driver;
|
||||
pub mod arch;
|
||||
|
||||
use spin::Mutex;
|
||||
use crate::arch::serial::{SerialConsole, init_serial_console, with_serial_console};
|
||||
use crate::arch::serial::{ConsoleWriter, SerialConsole, init_serial_console, with_serial_console};
|
||||
use crate::driver::graphics::font_render::render_text;
|
||||
use crate::driver::graphics::primitives::{circle_filled, circle_outline, rectangle_filled, rectangle_outline, triangle_outline};
|
||||
use crate::driver::graphics::base::rgb;
|
||||
@@ -36,26 +37,32 @@ static _START_MARKER: RequestsStartMarker = RequestsStartMarker::new();
|
||||
#[unsafe(link_section = ".requests_end_marker")]
|
||||
static _END_MARKER: RequestsEndMarker = RequestsEndMarker::new();
|
||||
|
||||
// #[macro_export]
|
||||
// macro_rules! print {
|
||||
// ($($arg:tt)*) => (with_framebuffer(|mut fb|{
|
||||
// with_serial_console(|serial_console| {
|
||||
// serial_console.render_text(&mut fb, format_args!($($arg)*));
|
||||
// });
|
||||
// }));
|
||||
// }
|
||||
#[macro_export]
|
||||
macro_rules! print {
|
||||
($($arg:tt)*) => {
|
||||
$crate::_print(core::format_args!($($arg)*))
|
||||
};
|
||||
}
|
||||
|
||||
// #[macro_export]
|
||||
// macro_rules! println {
|
||||
// () => ($crate::print!("\n"));
|
||||
// ($($arg:tt)*) => ($crate::print!("{}\n", format_args!($($arg)*)));
|
||||
// }
|
||||
#[macro_export]
|
||||
macro_rules! println {
|
||||
() => {
|
||||
$crate::_print(core::format_args!("\n"))
|
||||
};
|
||||
($($arg:tt)*) => {
|
||||
$crate::_print(core::format_args!("{}\n", core::format_args!($($arg)*)))
|
||||
};
|
||||
}
|
||||
|
||||
// #[doc(hidden)]
|
||||
// pub fn _print(args: fmt::Arguments) {
|
||||
// use core::fmt::Write;
|
||||
// WRITER.lock().write_fmt(args).unwrap();
|
||||
// }
|
||||
#[doc(hidden)]
|
||||
pub fn _print(args: core::fmt::Arguments) {
|
||||
with_framebuffer(|fb| {
|
||||
with_serial_console(|console| {
|
||||
let mut writer = ConsoleWriter { fb, console };
|
||||
let _ = writer.write_fmt(args);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn kmain() -> ! {
|
||||
@@ -95,6 +102,9 @@ fn rust_panic(_info: &core::panic::PanicInfo) -> ! {
|
||||
serial_console.render_text(&mut fb, "Message:");
|
||||
serial_console.render_text(&mut fb, message);
|
||||
}
|
||||
crate::println!("Kernel Panic! :C");
|
||||
crate::print!("Message: ");
|
||||
crate::println!("{}", _info);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user