use ratatui::prelude::*;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[cfg_attr(
feature = "serialization",
derive(serde::Serialize, serde::Deserialize)
)]
pub enum StatusLogLevel {
#[default]
Info,
Success,
Warning,
Error,
}
impl StatusLogLevel {
pub fn color(&self) -> Color {
match self {
StatusLogLevel::Info => Color::Cyan,
StatusLogLevel::Success => Color::Green,
StatusLogLevel::Warning => Color::Yellow,
StatusLogLevel::Error => Color::Red,
}
}
pub fn prefix(&self) -> &'static str {
match self {
StatusLogLevel::Info => "ℹ",
StatusLogLevel::Success => "✓",
StatusLogLevel::Warning => "⚠",
StatusLogLevel::Error => "✗",
}
}
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(
feature = "serialization",
derive(serde::Serialize, serde::Deserialize)
)]
pub struct StatusLogEntry {
pub(super) id: u64,
pub(super) message: String,
pub(super) level: StatusLogLevel,
pub(super) timestamp: Option<String>,
}
impl StatusLogEntry {
pub fn new(id: u64, message: impl Into<String>, level: StatusLogLevel) -> Self {
Self {
id,
message: message.into(),
level,
timestamp: None,
}
}
pub fn with_timestamp(
id: u64,
message: impl Into<String>,
level: StatusLogLevel,
timestamp: impl Into<String>,
) -> Self {
Self {
id,
message: message.into(),
level,
timestamp: Some(timestamp.into()),
}
}
pub fn id(&self) -> u64 {
self.id
}
pub fn message(&self) -> &str {
&self.message
}
pub fn level(&self) -> StatusLogLevel {
self.level
}
pub fn timestamp(&self) -> Option<&str> {
self.timestamp.as_deref()
}
}