2020-11-18 10:48:13 +04:00
|
|
|
use core::fmt::{self, Write};
|
2020-12-09 05:56:06 +04:00
|
|
|
|
|
|
|
const STDIN: usize = 0;
|
|
|
|
const STDOUT: usize = 1;
|
|
|
|
|
|
|
|
use super::{read, write};
|
2020-11-18 10:48:13 +04:00
|
|
|
|
|
|
|
struct Stdout;
|
|
|
|
|
|
|
|
impl Write for Stdout {
|
|
|
|
fn write_str(&mut self, s: &str) -> fmt::Result {
|
2020-12-09 05:56:06 +04:00
|
|
|
write(STDOUT, s.as_bytes());
|
2020-11-18 10:48:13 +04:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn print(args: fmt::Arguments) {
|
|
|
|
Stdout.write_fmt(args).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! print {
|
|
|
|
($fmt: literal $(, $($arg: tt)+)?) => {
|
|
|
|
$crate::console::print(format_args!($fmt $(, $($arg)+)?));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! println {
|
|
|
|
($fmt: literal $(, $($arg: tt)+)?) => {
|
|
|
|
$crate::console::print(format_args!(concat!($fmt, "\n") $(, $($arg)+)?));
|
|
|
|
}
|
2020-12-09 05:56:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn getchar() -> u8 {
|
|
|
|
let mut c = [0u8; 1];
|
|
|
|
read(STDIN, &mut c);
|
|
|
|
c[0]
|
|
|
|
}
|