mirror of
https://github.com/lune-org/lune.git
synced 2025-04-10 21:40:54 +01:00
Start implementing fmt module in lune-utils
This commit is contained in:
parent
5ad6b9a670
commit
b04c0c209d
5 changed files with 54 additions and 0 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1646,6 +1646,7 @@ dependencies = [
|
||||||
name = "lune-utils"
|
name = "lune-utils"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"console",
|
||||||
"dunce",
|
"dunce",
|
||||||
"mlua",
|
"mlua",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
|
|
@ -15,6 +15,7 @@ mlua = { version = "0.9.7", features = ["async"] }
|
||||||
|
|
||||||
tokio = { version = "1", default-features = false, features = ["fs"] }
|
tokio = { version = "1", default-features = false, features = ["fs"] }
|
||||||
|
|
||||||
|
console = "0.15"
|
||||||
dunce = "1.0"
|
dunce = "1.0"
|
||||||
once_cell = "1.17"
|
once_cell = "1.17"
|
||||||
path-clean = "1.0"
|
path-clean = "1.0"
|
||||||
|
|
48
crates/lune-utils/src/fmt/label.rs
Normal file
48
crates/lune-utils/src/fmt/label.rs
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
|
use console::{style, Color};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub enum Label {
|
||||||
|
Info,
|
||||||
|
Warn,
|
||||||
|
Error,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Label {
|
||||||
|
/**
|
||||||
|
Returns the name of the label in lowercase.
|
||||||
|
*/
|
||||||
|
#[must_use]
|
||||||
|
pub fn name(&self) -> &str {
|
||||||
|
match self {
|
||||||
|
Self::Info => "info",
|
||||||
|
Self::Warn => "warn",
|
||||||
|
Self::Error => "error",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the color of the label.
|
||||||
|
*/
|
||||||
|
#[must_use]
|
||||||
|
pub fn color(&self) -> Color {
|
||||||
|
match self {
|
||||||
|
Self::Info => Color::Blue,
|
||||||
|
Self::Warn => Color::Yellow,
|
||||||
|
Self::Error => Color::Red,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Label {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"{}{}{}",
|
||||||
|
style("[").dim(),
|
||||||
|
style(self.name().to_ascii_uppercase()).fg(self.color()),
|
||||||
|
style("]").dim()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
3
crates/lune-utils/src/fmt/mod.rs
Normal file
3
crates/lune-utils/src/fmt/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
mod label;
|
||||||
|
|
||||||
|
pub use self::label::Label;
|
|
@ -4,6 +4,7 @@ mod luaurc;
|
||||||
mod table_builder;
|
mod table_builder;
|
||||||
mod version_string;
|
mod version_string;
|
||||||
|
|
||||||
|
pub mod fmt;
|
||||||
pub mod path;
|
pub mod path;
|
||||||
|
|
||||||
pub use self::luaurc::LuauRc;
|
pub use self::luaurc::LuauRc;
|
||||||
|
|
Loading…
Add table
Reference in a new issue