refactored log
This commit is contained in:
+1
-25
@@ -1,7 +1,6 @@
|
||||
use color::Rgba8;
|
||||
use ratatui::layout::Rect;
|
||||
use ratatui::prelude::{Color, Line, Span, Style};
|
||||
use kiln_core::log::LogLine;
|
||||
use ratatui::prelude::Color;
|
||||
|
||||
/// Converts a core [`Rgba8`] color into a ratatui truecolor [`Color`].
|
||||
///
|
||||
@@ -11,29 +10,6 @@ pub fn rgba8_to_color(c: Rgba8) -> Color {
|
||||
Color::Rgb(c.r, c.g, c.b)
|
||||
}
|
||||
|
||||
/// Converts a core [`LogLine`] into a styled ratatui [`Line`] for display.
|
||||
///
|
||||
/// Each [`LogSpan`](kiln_core::log::LogSpan) becomes a ratatui [`Span`]; a span's
|
||||
/// foreground/background color is applied only when present, so `None` colors
|
||||
/// inherit the surrounding (default) style.
|
||||
pub fn logline_to_line(line: &LogLine) -> Line<'static> {
|
||||
let spans = line
|
||||
.spans
|
||||
.iter()
|
||||
.map(|s| {
|
||||
let mut style = Style::default();
|
||||
if let Some(fg) = s.fg {
|
||||
style = style.fg(rgba8_to_color(fg));
|
||||
}
|
||||
if let Some(bg) = s.bg {
|
||||
style = style.bg(rgba8_to_color(bg));
|
||||
}
|
||||
Span::styled(s.text.clone(), style)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
Line::from(spans)
|
||||
}
|
||||
|
||||
/// Returns true if two `Rect`s share at least one cell.
|
||||
pub fn rects_overlap(a: Rect, b: Rect) -> bool {
|
||||
a.x < b.x + b.width
|
||||
|
||||
Reference in New Issue
Block a user