commit da41585bef676857b6810f6ae680dd30519175d2
parent 8ce0b5c7b5c1a2b4135dc8e816512657f797fa1f
Author: Sylvia Ivory <git@sivory.net>
Date: Mon, 16 Mar 2026 00:28:10 -0700
Add color to journal
Diffstat:
3 files changed, 38 insertions(+), 22 deletions(-)
diff --git a/tools/src/sylveos/console.rs b/tools/src/sylveos/console.rs
@@ -4,7 +4,7 @@ use std::sync::{
};
use anyhow::Result;
-use ratatui::{buffer::Buffer, layout::Rect, widgets::Widget};
+use ratatui::{buffer::Buffer, layout::Rect, text::Line, widgets::Widget};
use tokio::io::{AsyncWriteExt, WriteHalf};
use tokio_serial::SerialStream;
@@ -156,10 +156,16 @@ impl ParagraphView for ConsoleWidget {
}
}
- fn get_paragraph_contexts(&self) -> String {
+ fn get_paragraph_contents(&self) -> Vec<Line<'_>> {
let state = self.state.read().unwrap();
let text = String::from_utf8_lossy(&state.buffer).to_string();
- format!("{text}{}", &state.user_input)
+
+ let full_text = format!("{text}{}", &state.user_input);
+
+ full_text
+ .lines()
+ .map(|l| Line::from(l.to_string()))
+ .collect()
}
}
diff --git a/tools/src/sylveos/journal.rs b/tools/src/sylveos/journal.rs
@@ -4,7 +4,13 @@ use std::sync::{
};
use chrono::{DateTime, Local};
-use ratatui::{buffer::Buffer, layout::Rect, widgets::Widget};
+use ratatui::{
+ buffer::Buffer,
+ layout::Rect,
+ style::Stylize,
+ text::{Line, Span},
+ widgets::Widget,
+};
use crate::sylveos::{ParagraphView, ParagraphViewState};
@@ -65,21 +71,24 @@ impl ParagraphView for JournalWidget {
}
}
- fn get_paragraph_contexts(&self) -> String {
+ fn get_paragraph_contents(&self) -> Vec<Line<'_>> {
let state = self.state.read().unwrap();
- let lines = state
+ state
.lines
.iter()
.map(|e| {
let timestamp = e.time.format("%H:%M:%S%.3f");
- format!("[{}] {} {}", timestamp, e.level.repr(), e.msg)
+ Line::from(vec![
+ timestamp.to_string().white(),
+ Span::from(" "),
+ e.level.repr(),
+ Span::from(" "),
+ Span::from(e.msg.clone()),
+ ])
})
- .collect::<Vec<_>>()
- .join("\n");
-
- lines
+ .collect()
}
}
@@ -108,15 +117,15 @@ pub enum LogLevel {
}
impl LogLevel {
- fn repr(self) -> &'static str {
+ fn repr(self) -> Span<'static> {
match self {
- LogLevel::Critical => "critical",
- LogLevel::Error => "error ",
- LogLevel::Warning => "warning ",
- LogLevel::Info => "info ",
- LogLevel::Debug => "debug ",
- LogLevel::Trace => "trace ",
- LogLevel::Invalid => "invalid ",
+ LogLevel::Critical => "critical".red(),
+ LogLevel::Error => "error ".red(),
+ LogLevel::Warning => "warning ".yellow(),
+ LogLevel::Info => "info ".green(),
+ LogLevel::Debug => "debug ".magenta(),
+ LogLevel::Trace => "trace ".gray(),
+ LogLevel::Invalid => "invalid ".dark_gray(),
}
}
diff --git a/tools/src/sylveos/paragraph_view.rs b/tools/src/sylveos/paragraph_view.rs
@@ -4,6 +4,7 @@ use ratatui::{
buffer::Buffer,
layout::Rect,
symbols::scrollbar,
+ text::Line,
widgets::{
Block, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState, StatefulWidget, Widget,
},
@@ -28,7 +29,7 @@ impl Default for ParagraphViewState {
pub trait ParagraphView {
fn get_view_state(&self) -> Arc<RwLock<ParagraphViewState>>;
- fn get_paragraph_contexts(&self) -> String;
+ fn get_paragraph_contents(&self) -> Vec<Line<'_>>;
fn get_title(&self) -> String;
fn get_subtitle(&self) -> Option<String> {
None
@@ -64,10 +65,10 @@ pub trait ParagraphView {
block = block.title_bottom(subtitle);
}
- let text = self.get_paragraph_contexts();
+ let text = self.get_paragraph_contents();
let inner_height = area.height.saturating_sub(2) as usize;
- let content_lines = text.lines().count();
+ let content_lines = text.len();
let max_scroll = content_lines.saturating_sub(inner_height);
if state.vertical_scroll >= max_scroll {