2023-07-29 15:27:16 +02:00
|
|
|
pub trait Ui {
|
|
|
|
fn write_str(&self, content: &str);
|
|
|
|
fn write_err_str(&self, content: &str);
|
|
|
|
|
|
|
|
fn write_str_ln(&self, content: &str);
|
|
|
|
fn write_err_str_ln(&self, content: &str);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub type DynUi = Box<dyn Ui + Send + Sync>;
|
|
|
|
|
|
|
|
impl Default for DynUi {
|
|
|
|
fn default() -> Self {
|
2023-07-31 13:34:23 +02:00
|
|
|
Box::<ConsoleUi>::default()
|
2023-07-29 15:27:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-31 13:34:23 +02:00
|
|
|
#[derive(Default)]
|
2023-08-01 15:34:24 +02:00
|
|
|
pub struct ConsoleUi {}
|
2023-07-29 15:27:16 +02:00
|
|
|
|
2023-07-30 01:39:28 +02:00
|
|
|
#[allow(dead_code)]
|
2023-07-29 15:27:16 +02:00
|
|
|
impl ConsoleUi {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
Self::default()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<ConsoleUi> for DynUi {
|
|
|
|
fn from(value: ConsoleUi) -> Self {
|
|
|
|
Box::new(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Ui for ConsoleUi {
|
|
|
|
fn write_str(&self, content: &str) {
|
|
|
|
print!("{}", content)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn write_err_str(&self, content: &str) {
|
|
|
|
eprint!("{}", content)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn write_str_ln(&self, content: &str) {
|
|
|
|
println!("{}", content)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn write_err_str_ln(&self, content: &str) {
|
|
|
|
eprintln!("{}", content)
|
|
|
|
}
|
|
|
|
}
|