refactor: move commands and misc out of main binary package

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2023-08-01 15:34:24 +02:00
parent 8b83b9c14d
commit c7793f7422
24 changed files with 580 additions and 460 deletions

View File

@@ -0,0 +1,49 @@
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 {
Box::<ConsoleUi>::default()
}
}
#[derive(Default)]
pub struct ConsoleUi {}
#[allow(dead_code)]
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)
}
}