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

@@ -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);
}