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
+9 -13
View File
@@ -9,10 +9,10 @@
use ratatui::crossterm::event::{
KeyboardEnhancementFlags, PopKeyboardEnhancementFlags, PushKeyboardEnhancementFlags,
};
use color::Rgba8;
use kiln_core::log::LogLine;
use ratatui::crossterm::execute;
use ratatui::crossterm::terminal::supports_keyboard_enhancement;
use ratatui::style::{Color, Style};
use ratatui::text::{Line, Span};
use std::io;
/// The input capabilities of the host terminal, detected once at startup.
@@ -48,15 +48,16 @@ impl TerminalCaps {
}
}
/// A one-line styled summary for the UI, e.g. `"truecolor · enhanced input"`.
/// A one-line styled summary of terminal capabilities as a [`LogLine`],
/// e.g. `"truecolor · enhanced input"`, seeded into the game log at startup.
///
/// When truecolor is available the word "truecolor" is rendered with each
/// letter a different rainbow color — a fitting flex, since only a terminal
/// that can show per-cell RGB can display it. Otherwise the color word is the
/// plain `"256-color"`. The input descriptor is always drawn in the default
/// color.
pub fn summary_line(&self) -> Line<'static> {
let mut spans: Vec<Span<'static>> = vec![Span::raw(" ")];
pub fn status_logline(&self) -> LogLine {
let mut line = LogLine::new();
if self.truecolor {
// Rotate the hue across the letters so each gets a distinct spectrum color.
@@ -64,13 +65,10 @@ impl TerminalCaps {
let n = word.chars().count();
for (i, ch) in word.chars().enumerate() {
let (r, g, b) = hue_to_rgb(i as f32 / n as f32 * 360.0);
spans.push(Span::styled(
ch.to_string(),
Style::default().fg(Color::Rgb(r, g, b)),
));
line = line.push(ch.to_string(), Some(Rgba8 { r, g, b, a: 255 }), None);
}
} else {
spans.push(Span::raw("256-color"));
line = line.push("256-color", None, None);
}
let input = if self.keyboard_enhancement {
@@ -78,9 +76,7 @@ impl TerminalCaps {
} else {
"legacy input"
};
spans.push(Span::raw(format!(" · {input} ")));
Line::from(spans)
line.push(format!(" · {input}"), None, None)
}
}