feat: Improve output of tui. From p-r tui-score-info (#11)

WIP: formatted score debug print into a table with a name header and the score information below
Co-authored-by: Jean-Gabriel Gill-Couture <jg@nationtech.io>
Reviewed-on: NationTech/harmony#11
Reviewed-by: johnride <jg@nationtech.io>
Co-authored-by: Willem <wrolleman@nationtech.io>
Co-committed-by: Willem <wrolleman@nationtech.io>
This commit is contained in:
2025-04-23 14:54:32 +00:00
committed by johnride
parent abd20b96a2
commit eeafa086f3
10 changed files with 277 additions and 21 deletions

View File

@@ -16,3 +16,5 @@ color-eyre = "0.6.3"
tokio-stream = "0.1.17"
tui-logger = "0.14.1"
log-panics = "2.1.0"
serde-value.workspace = true
serde_json = "1.0.140"

View File

@@ -159,12 +159,13 @@ impl<T: Topology + std::fmt::Debug + Send + Sync + 'static> HarmonyTUI<T> {
frame.render_widget(&help_block, help_area);
frame.render_widget(HelpWidget::new(), help_block.inner(help_area));
let [list_area, output_area] =
let [list_area, logger_area] =
Layout::horizontal([Constraint::Min(30), Constraint::Percentage(100)]).areas(app_area);
let block = Block::default().borders(Borders::RIGHT);
frame.render_widget(&block, list_area);
self.score.render(list_area, frame);
let tui_logger = tui_logger::TuiLoggerWidget::default()
.style_error(Style::default().fg(Color::Red))
.style_warn(Style::default().fg(Color::LightRed))
@@ -172,9 +173,9 @@ impl<T: Topology + std::fmt::Debug + Send + Sync + 'static> HarmonyTUI<T> {
.style_debug(Style::default().fg(Color::Gray))
.style_trace(Style::default().fg(Color::Gray))
.state(&self.tui_state);
frame.render_widget(tui_logger, output_area)
}
frame.render_widget(tui_logger, logger_area);
}
fn scores_list(maestro: &Maestro<T>) -> Vec<Box<dyn Score<T>>> {
let scores = maestro.scores();
let scores_read = scores.read().expect("Should be able to read scores");

View File

@@ -1,5 +1,6 @@
use std::sync::{Arc, RwLock};
use crate::HarmonyTuiEvent;
use crossterm::event::{Event, KeyCode, KeyEventKind};
use harmony::{score::Score, topology::Topology};
use log::{info, warn};
@@ -11,8 +12,6 @@ use ratatui::{
};
use tokio::sync::mpsc;
use crate::HarmonyTuiEvent;
#[derive(Debug)]
enum ExecutionState {
INITIATED,
@@ -53,23 +52,27 @@ impl<T: Topology + std::fmt::Debug> ScoreListWidget<T> {
}
pub(crate) fn launch_execution(&mut self) {
let list_read = self.list_state.read().unwrap();
if let Some(index) = list_read.selected() {
let score = self
.scores
.get(index)
.expect("List state should always match with internal Vec");
if let Some(score) = self.get_selected_score() {
self.execution = Some(Execution {
state: ExecutionState::INITIATED,
score: score.clone_box(),
});
info!("{:#?}\n\nConfirm Execution (Press y/n)", score);
info!("{}\n\nConfirm Execution (Press y/n)", score.name());
info!("{}", score.print_score_details());
} else {
warn!("No Score selected, nothing to launch");
}
}
pub(crate) fn get_selected_score(&self) -> Option<Box<dyn Score<T>>> {
let list_read = self.list_state.read().unwrap();
if let Some(index) = list_read.selected() {
self.scores.get(index).map(|s| s.clone_box())
} else {
None
}
}
pub(crate) fn scroll_down(&self) {
self.list_state.write().unwrap().scroll_down_by(1);
}