refactor: move commands and misc out of main binary package
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
49
crates/cuddle-please-misc/src/ui.rs
Normal file
49
crates/cuddle-please-misc/src/ui.rs
Normal 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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user