hex_patch/app/log/
log_line.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use ratatui::text::{Line, Span};

use super::notification::NotificationLevel;
use crate::app::settings::color_settings::ColorSettings;

#[derive(Debug, Clone)]
pub struct LogLine {
    pub level: NotificationLevel,
    pub message: String,
}

impl LogLine {
    pub fn new(level: NotificationLevel, message: String) -> Self {
        LogLine { level, message }
    }

    pub fn to_line(&self, color_settings: &ColorSettings) -> Line<'static> {
        let mut line = Line::default();
        let style = match self.level {
            NotificationLevel::Debug => color_settings.log_debug,
            NotificationLevel::Info => color_settings.log_info,
            NotificationLevel::Warning => color_settings.log_warning,
            NotificationLevel::Error => color_settings.log_error,
            _ => color_settings.log_info,
        };
        line.spans.push(Span::styled(self.level.to_string(), style));
        line.spans
            .push(Span::styled(" ", color_settings.log_message));
        line.spans.push(Span::styled(
            self.message.clone(),
            color_settings.log_message,
        ));
        line.left_aligned()
    }
}