hex_patch/app/log/
log_line.rs1use ratatui::text::{Line, Span};
2
3use super::notification::NotificationLevel;
4use crate::app::settings::color_settings::ColorSettings;
5
6#[derive(Debug, Clone)]
7pub struct LogLine {
8 pub level: NotificationLevel,
9 pub message: String,
10}
11
12impl LogLine {
13 pub fn new(level: NotificationLevel, message: String) -> Self {
14 LogLine { level, message }
15 }
16
17 pub fn to_line(&self, color_settings: &ColorSettings) -> Line<'static> {
18 let mut line = Line::default();
19 let style = match self.level {
20 NotificationLevel::Debug => color_settings.log_debug,
21 NotificationLevel::Info => color_settings.log_info,
22 NotificationLevel::Warning => color_settings.log_warning,
23 NotificationLevel::Error => color_settings.log_error,
24 _ => color_settings.log_info,
25 };
26 line.spans.push(Span::styled(self.level.to_string(), style));
27 line.spans
28 .push(Span::styled(" ", color_settings.log_message));
29 line.spans.push(Span::styled(
30 self.message.clone(),
31 color_settings.log_message,
32 ));
33 line.left_aligned()
34 }
35}