wip: trying to output in a better format

This commit is contained in:
Willem 2025-04-11 15:49:09 -04:00
parent 4f8523ab69
commit f9d1935c71

View File

@ -1,6 +1,7 @@
mod widget; mod widget;
use log::{debug, error, info}; use log::{debug, error, info};
use prettytable::{Table, cell, row};
use tokio::sync::mpsc; use tokio::sync::mpsc;
use tokio_stream::StreamExt; use tokio_stream::StreamExt;
use tui_logger::{TuiWidgetEvent, TuiWidgetState}; use tui_logger::{TuiWidgetEvent, TuiWidgetState};
@ -13,7 +14,8 @@ use harmony::{maestro::Maestro, score::Score, topology::Topology};
use ratatui::{ use ratatui::{
self, Frame, self, Frame,
layout::{Constraint, Layout, Position}, layout::{Constraint, Layout, Position},
style::{Color, Style}, style::{Color, Modifier, Style},
text::{Line, Span, Text},
widgets::{Block, Borders, Paragraph, Wrap}, widgets::{Block, Borders, Paragraph, Wrap},
}; };
@ -177,18 +179,41 @@ impl<T: Topology + std::fmt::Debug + Send + Sync + 'static> HarmonyTUI<T> {
.state(&self.tui_state); .state(&self.tui_state);
frame.render_widget(tui_logger, logger_area); frame.render_widget(tui_logger, logger_area);
let info_block = Block::default().borders(Borders::ALL).title("Score Details"); let info_block = Block::default()
.borders(Borders::ALL)
.title("Score Details");
let scores = &self.score.get_selected_score(); let mut text_output = Text::default();
let mut info = String::new(); if let Some(score) = self.score.get_selected_score() {
scores.into_iter().for_each(|score| { //scores.into_iter().for_each(|score| {
info += &score.display_value(); // info += &score.display_value();
}); //});
let info_paragraph = Paragraph::new(info) text_output = self.format_score_for_output(score);
}
let info_paragraph = Paragraph::new(text_output)
.block(info_block) .block(info_block)
.wrap(Wrap { trim: true }); .wrap(Wrap { trim: true });
frame.render_widget(info_paragraph, info_area); frame.render_widget(info_paragraph, info_area);
} }
//TODO trying to format the output in a way that looks good in the debug output
//this has not changed anything so far
fn format_score_for_output(&self, score: Box<dyn Score<T>>) -> Text<'_> {
let mut text = Text::default();
let name_line = Line::from(vec![Span::styled(
score.name(),
Style::default().add_modifier(Modifier::BOLD),
)]);
text.lines.push(name_line);
let val = score.serialize();
let pretty = score.print_value(&val, 0);
for line in pretty.lines() {
text.lines.push(Line::from(line.to_string()));
}
text
}
fn scores_list(maestro: &Maestro<T>) -> Vec<Box<dyn Score<T>>> { fn scores_list(maestro: &Maestro<T>) -> Vec<Box<dyn Score<T>>> {
let scores = maestro.scores(); let scores = maestro.scores();