forked from github-starred/komodo
move formatting to shared lib
This commit is contained in:
10
lib/formatting/Cargo.toml
Normal file
10
lib/formatting/Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "formatting"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
authors.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
homepage.workspace = true
|
||||
|
||||
[dependencies]
|
||||
32
lib/formatting/src/lib.rs
Normal file
32
lib/formatting/src/lib.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
pub fn muted(content: impl std::fmt::Display) -> String {
|
||||
format!("<span class=\"text-muted-foreground\">{content}</span>")
|
||||
}
|
||||
|
||||
pub fn bold(content: impl std::fmt::Display) -> String {
|
||||
format!("<span class=\"font-bold\">{content}</span>")
|
||||
}
|
||||
|
||||
pub fn colored(
|
||||
content: impl std::fmt::Display,
|
||||
color: Color,
|
||||
) -> String {
|
||||
format!("<span class=\"{color}\">{content}</span>")
|
||||
}
|
||||
|
||||
pub enum Color {
|
||||
Red,
|
||||
Green,
|
||||
Blue,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Color {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Color::Red => f.write_str("text-red-700 dark:text-red-400"),
|
||||
Color::Green => {
|
||||
f.write_str("text-green-700 dark:text-green-400")
|
||||
}
|
||||
Color::Blue => f.write_str("text-blue-700 dark:text-blue-400"),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user