Log panel

This commit is contained in:
2026-06-03 22:46:54 -05:00
parent de1870432f
commit 0187162e85
6 changed files with 262 additions and 53 deletions
+26 -1
View File
@@ -8,9 +8,11 @@
use crate::cp437::tile_to_char;
use color::Rgba8;
use kiln_core::game::{Board, Glyph};
use kiln_core::log::LogLine;
use ratatui::buffer::Buffer;
use ratatui::layout::Rect;
use ratatui::style::Color;
use ratatui::style::{Color, Style};
use ratatui::text::{Line, Span};
use ratatui::widgets::Widget;
/// Converts a core [`Rgba8`] color into a ratatui truecolor [`Color`].
@@ -21,6 +23,29 @@ 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)
}
/// A ratatui widget that draws a [`Board`] (with objects and the player) into a
/// rectangular area, scrolled so the player stays visible on larger boards.
pub struct BoardWidget<'a> {