1
0
Fork 0
forked from koniifer/ableos
ableos-framebuffer/ableos/src/print.rs

57 lines
1.4 KiB
Rust
Raw Normal View History

2021-11-16 00:09:27 -06:00
pub struct Stdout;
2021-11-23 05:53:06 -06:00
use core::fmt::{Arguments, Error};
2021-11-16 00:09:27 -06:00
impl Stdout {
pub fn write_fmt(&mut self, arg: Arguments<'_>) /*-> Result<(), Error> */
{
core::fmt::Write::write_fmt(self, arg);
// Ok(())
}
}
impl core::fmt::Write for Stdout {
#[cfg(target_arch = "aarch64")]
fn write_str(&mut self, s: &str) -> Result<(), Error> {
// Don't actually print anything yet lmao
Ok(())
}
#[cfg(target_arch = "x86_64")]
fn write_str(&mut self, s: &str) -> Result<(), Error> {
use crate::kprint;
// FIXME: causes issues
kprint!("{}", s);
Ok(())
}
#[cfg(target_arch = "riscv64")]
fn write_str(&mut self, s: &str) -> Result<(), Error> {
Ok(())
}
2021-11-27 09:19:08 -06:00
fn write_char(&mut self, c: char) -> core::fmt::Result {
self.write_str(c.encode_utf8(&mut [0; 4]))
}
fn write_fmt(mut self: &mut Self, args: Arguments<'_>) -> core::fmt::Result {
core::fmt::write(&mut self, args)
}
2021-11-16 00:09:27 -06:00
}
#[macro_export]
macro_rules! print {
() => {
::core::writeln!($crate::print::Stdout, "")
};
($($tt:tt)*) => {
::core::write!($crate::print::Stdout, $($tt)*)
};
}
#[macro_export]
macro_rules! println {
() =>{
// ::core::writeln!($crate::print::Stdout, "\n")
panic![];
};
($($tt:tt)*) => {
::core::writeln!($crate::print::Stdout, $($tt)*)
// panic![];
};
}