formatted score debug into table, removed score info box from tui
This commit is contained in:
parent
f9d1935c71
commit
ffe175df1b
@ -4,7 +4,7 @@ use serde_value::Value;
|
|||||||
use super::{interpret::Interpret, topology::Topology};
|
use super::{interpret::Interpret, topology::Topology};
|
||||||
|
|
||||||
pub trait Score<T: Topology>:
|
pub trait Score<T: Topology>:
|
||||||
std::fmt::Debug + DisplayValues<T> + Send + Sync + CloneBoxScore<T> + SerializeScore<T>
|
std::fmt::Debug + ScoreToString<T> + Send + Sync + CloneBoxScore<T> + SerializeScore<T>
|
||||||
{
|
{
|
||||||
fn create_interpret(&self) -> Box<dyn Interpret<T>>;
|
fn create_interpret(&self) -> Box<dyn Interpret<T>>;
|
||||||
fn name(&self) -> String;
|
fn name(&self) -> String;
|
||||||
@ -40,25 +40,25 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait DisplayValues<T: Topology> {
|
pub trait ScoreToString<T: Topology> {
|
||||||
fn display_value(&self) -> String;
|
fn print_score_details(&self) -> String;
|
||||||
fn print_value(&self, val: &Value, indent: usize) -> String;
|
fn format_value_as_string(&self, val: &Value, indent: usize) -> String;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, T> DisplayValues<T> for S
|
impl<S, T> ScoreToString<T> for S
|
||||||
where
|
where
|
||||||
T: Topology,
|
T: Topology,
|
||||||
S: Score<T> + 'static,
|
S: Score<T> + 'static,
|
||||||
{
|
{
|
||||||
fn display_value(&self) -> String {
|
fn print_score_details(&self) -> String {
|
||||||
let mut output = String::new();
|
let mut output = String::new();
|
||||||
output += &format!("{}\n", &self.name());
|
output += "\n";
|
||||||
output += &self.print_value(&self.serialize(), 0);
|
output += &self.format_value_as_string(&self.serialize(), 0);
|
||||||
output += "\n";
|
output += "\n";
|
||||||
output
|
output
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_value(&self, val: &Value, indent: usize) -> String {
|
fn format_value_as_string(&self, val: &Value, indent: usize) -> String {
|
||||||
let pad = " ".repeat(indent * 2);
|
let pad = " ".repeat(indent * 2);
|
||||||
let mut output = String::new();
|
let mut output = String::new();
|
||||||
|
|
||||||
@ -82,14 +82,14 @@ where
|
|||||||
Value::Option(opt) => match opt {
|
Value::Option(opt) => match opt {
|
||||||
Some(inner) => {
|
Some(inner) => {
|
||||||
output += &format!("{}Option:\n", pad);
|
output += &format!("{}Option:\n", pad);
|
||||||
output += &self.print_value(inner, indent + 1);
|
output += &self.format_value_as_string(inner, indent + 1);
|
||||||
}
|
}
|
||||||
None => output += &format!("{}None\n", pad),
|
None => output += &format!("{}None\n", pad),
|
||||||
},
|
},
|
||||||
|
|
||||||
Value::Newtype(inner) => {
|
Value::Newtype(inner) => {
|
||||||
output += &format!("{}Newtype:\n", pad);
|
output += &format!("{}Newtype:\n", pad);
|
||||||
output += &self.print_value(inner, indent + 1);
|
output += &self.format_value_as_string(inner, indent + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value::Seq(seq) => {
|
Value::Seq(seq) => {
|
||||||
@ -98,7 +98,7 @@ where
|
|||||||
} else {
|
} else {
|
||||||
output += &format!("{}[\n", pad);
|
output += &format!("{}[\n", pad);
|
||||||
for item in seq {
|
for item in seq {
|
||||||
output += &self.print_value(item, indent + 1);
|
output += &self.format_value_as_string(item, indent + 1);
|
||||||
}
|
}
|
||||||
output += &format!("{}]\n", pad);
|
output += &format!("{}]\n", pad);
|
||||||
}
|
}
|
||||||
@ -112,7 +112,7 @@ where
|
|||||||
"{}+--------------------------+----------------------------+\n",
|
"{}+--------------------------+----------------------------+\n",
|
||||||
pad
|
pad
|
||||||
);
|
);
|
||||||
output += &format!("{}| {:<24} | {:<26} |\n", pad, "Key", "Value");
|
output += &format!("{}| {:<24} | {:<26} |\n", pad, "score_name", self.name());
|
||||||
output += &format!(
|
output += &format!(
|
||||||
"{}+--------------------------+----------------------------+\n",
|
"{}+--------------------------+----------------------------+\n",
|
||||||
pad
|
pad
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
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};
|
||||||
@ -14,9 +13,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, Modifier, Style},
|
style::{Color, Style},
|
||||||
text::{Line, Span, Text},
|
widgets::{Block, Borders},
|
||||||
widgets::{Block, Borders, Paragraph, Wrap},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub mod tui {
|
pub mod tui {
|
||||||
@ -161,15 +159,13 @@ impl<T: Topology + std::fmt::Debug + Send + Sync + 'static> HarmonyTUI<T> {
|
|||||||
frame.render_widget(&help_block, help_area);
|
frame.render_widget(&help_block, help_area);
|
||||||
frame.render_widget(HelpWidget::new(), help_block.inner(help_area));
|
frame.render_widget(HelpWidget::new(), help_block.inner(help_area));
|
||||||
|
|
||||||
let [list_area, right_area] =
|
let [list_area, logger_area] =
|
||||||
Layout::horizontal([Constraint::Min(30), Constraint::Percentage(100)]).areas(app_area);
|
Layout::horizontal([Constraint::Min(30), Constraint::Percentage(100)]).areas(app_area);
|
||||||
|
|
||||||
let block = Block::default().borders(Borders::RIGHT);
|
let block = Block::default().borders(Borders::RIGHT);
|
||||||
frame.render_widget(&block, list_area);
|
frame.render_widget(&block, list_area);
|
||||||
self.score.render(list_area, frame);
|
self.score.render(list_area, frame);
|
||||||
|
|
||||||
let [logger_area, info_area] =
|
|
||||||
Layout::vertical([Constraint::Min(30), Constraint::Percentage(100)]).areas(right_area);
|
|
||||||
let tui_logger = tui_logger::TuiLoggerWidget::default()
|
let tui_logger = tui_logger::TuiLoggerWidget::default()
|
||||||
.style_error(Style::default().fg(Color::Red))
|
.style_error(Style::default().fg(Color::Red))
|
||||||
.style_warn(Style::default().fg(Color::LightRed))
|
.style_warn(Style::default().fg(Color::LightRed))
|
||||||
@ -179,42 +175,7 @@ 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 mut text_output = Text::default();
|
|
||||||
if let Some(score) = self.score.get_selected_score() {
|
|
||||||
//scores.into_iter().for_each(|score| {
|
|
||||||
// info += &score.display_value();
|
|
||||||
//});
|
|
||||||
text_output = self.format_score_for_output(score);
|
|
||||||
}
|
|
||||||
let info_paragraph = Paragraph::new(text_output)
|
|
||||||
.block(info_block)
|
|
||||||
.wrap(Wrap { trim: true });
|
|
||||||
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();
|
||||||
let scores_read = scores.read().expect("Should be able to read scores");
|
let scores_read = scores.read().expect("Should be able to read scores");
|
||||||
|
|||||||
@ -58,7 +58,7 @@ impl<T: Topology + std::fmt::Debug> ScoreListWidget<T> {
|
|||||||
score: score.clone_box(),
|
score: score.clone_box(),
|
||||||
});
|
});
|
||||||
info!("{:#?}\n\nConfirm Execution (Press y/n)", score);
|
info!("{:#?}\n\nConfirm Execution (Press y/n)", score);
|
||||||
info!("{:#?}", score.display_value());
|
info!("{}", score.print_score_details());
|
||||||
} else {
|
} else {
|
||||||
warn!("No Score selected, nothing to launch");
|
warn!("No Score selected, nothing to launch");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user