wip:made score details box output information for highlighted score, worked on outputing score info in log output
This commit is contained in:
parent
6ddf48591b
commit
4f8523ab69
@ -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 + Send + Sync + CloneBoxScore<T> + SerializeScore<T>
|
std::fmt::Debug + DisplayValues<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;
|
||||||
@ -39,3 +39,110 @@ where
|
|||||||
Box::new(self.clone())
|
Box::new(self.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait DisplayValues<T: Topology> {
|
||||||
|
fn display_value(&self) -> String;
|
||||||
|
fn print_value(&self, val: &Value, indent: usize) -> String;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S, T> DisplayValues<T> for S
|
||||||
|
where
|
||||||
|
T: Topology,
|
||||||
|
S: Score<T> + 'static,
|
||||||
|
{
|
||||||
|
fn display_value(&self) -> String {
|
||||||
|
let mut output = String::new();
|
||||||
|
output += &format!("{}\n", &self.name());
|
||||||
|
output += &self.print_value(&self.serialize(), 0);
|
||||||
|
output += "\n";
|
||||||
|
output
|
||||||
|
}
|
||||||
|
|
||||||
|
fn print_value(&self, val: &Value, indent: usize) -> String {
|
||||||
|
let pad = " ".repeat(indent * 2);
|
||||||
|
let mut output = String::new();
|
||||||
|
|
||||||
|
match val {
|
||||||
|
Value::Bool(b) => output += &format!("{}{}\n", pad, b),
|
||||||
|
Value::U8(u) => output += &format!("{}{}\n", pad, u),
|
||||||
|
Value::U16(u) => output += &format!("{}{}\n", pad, u),
|
||||||
|
Value::U32(u) => output += &format!("{}{}\n", pad, u),
|
||||||
|
Value::U64(u) => output += &format!("{}{}\n", pad, u),
|
||||||
|
Value::I8(i) => output += &format!("{}{}\n", pad, i),
|
||||||
|
Value::I16(i) => output += &format!("{}{}\n", pad, i),
|
||||||
|
Value::I32(i) => output += &format!("{}{}\n", pad, i),
|
||||||
|
Value::I64(i) => output += &format!("{}{}\n", pad, i),
|
||||||
|
Value::F32(f) => output += &format!("{}{}\n", pad, f),
|
||||||
|
Value::F64(f) => output += &format!("{}{}\n", pad, f),
|
||||||
|
Value::Char(c) => output += &format!("{}{}\n", pad, c),
|
||||||
|
Value::String(s) => output += &format!("{}{}\n", pad, s),
|
||||||
|
Value::Unit => output += &format!("{}<unit>\n", pad),
|
||||||
|
Value::Bytes(bytes) => output += &format!("{}{:?}\n", pad, bytes),
|
||||||
|
|
||||||
|
Value::Option(opt) => match opt {
|
||||||
|
Some(inner) => {
|
||||||
|
output += &format!("{}Option:\n", pad);
|
||||||
|
output += &self.print_value(inner, indent + 1);
|
||||||
|
}
|
||||||
|
None => output += &format!("{}None\n", pad),
|
||||||
|
},
|
||||||
|
|
||||||
|
Value::Newtype(inner) => {
|
||||||
|
output += &format!("{}Newtype:\n", pad);
|
||||||
|
output += &self.print_value(inner, indent + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
Value::Seq(seq) => {
|
||||||
|
if seq.is_empty() {
|
||||||
|
output += &format!("{}[]\n", pad);
|
||||||
|
} else {
|
||||||
|
output += &format!("{}[\n", pad);
|
||||||
|
for item in seq {
|
||||||
|
output += &self.print_value(item, indent + 1);
|
||||||
|
}
|
||||||
|
output += &format!("{}]\n", pad);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Value::Map(map) => {
|
||||||
|
if map.is_empty() {
|
||||||
|
output += &format!("{}<empty map>\n", pad);
|
||||||
|
} else {
|
||||||
|
output += &format!(
|
||||||
|
"{}+--------------------------+----------------------------+\n",
|
||||||
|
pad
|
||||||
|
);
|
||||||
|
output += &format!("{}| {:<24} | {:<26} |\n", pad, "Key", "Value");
|
||||||
|
output += &format!(
|
||||||
|
"{}+--------------------------+----------------------------+\n",
|
||||||
|
pad
|
||||||
|
);
|
||||||
|
|
||||||
|
for (k, v) in map {
|
||||||
|
let key_str = match k {
|
||||||
|
Value::String(s) => s.clone(),
|
||||||
|
other => format!("{:?}", other),
|
||||||
|
};
|
||||||
|
let val_str = match v {
|
||||||
|
Value::String(s) => s.clone(),
|
||||||
|
Value::Bool(b) => b.to_string(),
|
||||||
|
Value::Option(Some(inner)) => format!("{:?}", inner),
|
||||||
|
Value::Option(None) => "None".to_string(),
|
||||||
|
Value::Seq(seq) => format!("{:?}", seq),
|
||||||
|
_ => format!("{:?}", v),
|
||||||
|
};
|
||||||
|
|
||||||
|
output += &format!("{}| {:<24} | {:<26} |\n", pad, key_str, val_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
output += &format!(
|
||||||
|
"{}+--------------------------+----------------------------+\n\n",
|
||||||
|
pad
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
output
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -177,10 +177,13 @@ 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 = self.score.display_value();
|
|
||||||
//let info = self.score.display_value();
|
let scores = &self.score.get_selected_score();
|
||||||
let info_block = Block::default().borders(Borders::ALL).title("Scores Info");
|
let mut info = String::new();
|
||||||
|
scores.into_iter().for_each(|score| {
|
||||||
|
info += &score.display_value();
|
||||||
|
});
|
||||||
let info_paragraph = Paragraph::new(info)
|
let info_paragraph = Paragraph::new(info)
|
||||||
.block(info_block)
|
.block(info_block)
|
||||||
.wrap(Wrap { trim: true });
|
.wrap(Wrap { trim: true });
|
||||||
|
|||||||
@ -1,6 +1,3 @@
|
|||||||
use ratatui::layout::Constraint;
|
|
||||||
use serde_value::Value;
|
|
||||||
use std::collections::BTreeMap;
|
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
use crate::HarmonyTuiEvent;
|
use crate::HarmonyTuiEvent;
|
||||||
@ -10,10 +7,8 @@ use log::{info, warn};
|
|||||||
use ratatui::{
|
use ratatui::{
|
||||||
Frame,
|
Frame,
|
||||||
layout::Rect,
|
layout::Rect,
|
||||||
style::{Modifier, Style, Stylize},
|
style::{Style, Stylize},
|
||||||
widgets::{
|
widgets::{List, ListItem, ListState, StatefulWidget, Widget},
|
||||||
Block, Borders, Cell, List, ListItem, ListState, Row, StatefulWidget, Table, Widget,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
@ -57,136 +52,25 @@ impl<T: Topology + std::fmt::Debug> ScoreListWidget<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn launch_execution(&mut self) {
|
pub(crate) fn launch_execution(&mut self) {
|
||||||
let list_read = self.list_state.read().unwrap();
|
if let Some(score) = self.get_selected_score() {
|
||||||
if let Some(index) = list_read.selected() {
|
|
||||||
let score = self
|
|
||||||
.scores
|
|
||||||
.get(index)
|
|
||||||
.expect("List state should always match with internal Vec");
|
|
||||||
|
|
||||||
self.execution = Some(Execution {
|
self.execution = Some(Execution {
|
||||||
state: ExecutionState::INITIATED,
|
state: ExecutionState::INITIATED,
|
||||||
score: score.clone_box(),
|
score: score.clone_box(),
|
||||||
});
|
});
|
||||||
//TODO: need to format the output of the score.serialize()
|
|
||||||
//currently just dumps to MAP() and handle _
|
|
||||||
//maybe columns
|
|
||||||
//https://arcnmx.github.io/serde-value/serde_value/enum.Value.html
|
|
||||||
info!("{:#?}\n\nConfirm Execution (Press y/n)", score);
|
info!("{:#?}\n\nConfirm Execution (Press y/n)", score);
|
||||||
|
info!("{:#?}", score.display_value());
|
||||||
} else {
|
} else {
|
||||||
warn!("No Score selected, nothing to launch");
|
warn!("No Score selected, nothing to launch");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//TODO working on match statement to output serialized value
|
|
||||||
//want to try and build a fn for a few types that are represtendd in DNSscore
|
pub(crate) fn get_selected_score(&self) -> Option<Box<dyn Score<T>>> {
|
||||||
//and output them by calling fn display_values in the about fn
|
let list_read = self.list_state.read().unwrap();
|
||||||
//
|
if let Some(index) = list_read.selected() {
|
||||||
//currently outputs info about all available scores, not quite
|
self.scores.get(index).map(|s| s.clone_box())
|
||||||
//looking to output info about the selected score and subscores
|
} else {
|
||||||
//
|
None
|
||||||
|
|
||||||
fn print_value(&self, val: &Value, indent: usize) -> String {
|
|
||||||
let pad = " ".repeat(indent * 2);
|
|
||||||
let mut output = String::new();
|
|
||||||
|
|
||||||
match val {
|
|
||||||
Value::Bool(b) => output += &format!("{}{}\n", pad, b),
|
|
||||||
Value::U8(u) => output += &format!("{}{}\n", pad, u),
|
|
||||||
Value::U16(u) => output += &format!("{}{}\n", pad, u),
|
|
||||||
Value::U32(u) => output += &format!("{}{}\n", pad, u),
|
|
||||||
Value::U64(u) => output += &format!("{}{}\n", pad, u),
|
|
||||||
Value::I8(i) => output += &format!("{}{}\n", pad, i),
|
|
||||||
Value::I16(i) => output += &format!("{}{}\n", pad, i),
|
|
||||||
Value::I32(i) => output += &format!("{}{}\n", pad, i),
|
|
||||||
Value::I64(i) => output += &format!("{}{}\n", pad, i),
|
|
||||||
Value::F32(f) => output += &format!("{}{}\n", pad, f),
|
|
||||||
Value::F64(f) => output += &format!("{}{}\n", pad, f),
|
|
||||||
Value::Char(c) => output += &format!("{}{}\n", pad, c),
|
|
||||||
Value::String(s) => output += &format!("{}{}\n", pad, s),
|
|
||||||
Value::Unit => output += &format!("{}<unit>\n", pad),
|
|
||||||
Value::Bytes(bytes) => output += &format!("{}{:?}\n", pad, bytes),
|
|
||||||
|
|
||||||
Value::Option(opt) => match opt {
|
|
||||||
Some(inner) => {
|
|
||||||
output += &format!("{}Option:\n", pad);
|
|
||||||
output += &self.print_value(inner, indent + 1);
|
|
||||||
}
|
|
||||||
None => output += &format!("{}None\n", pad),
|
|
||||||
},
|
|
||||||
|
|
||||||
Value::Newtype(inner) => {
|
|
||||||
output += &format!("{}Newtype:\n", pad);
|
|
||||||
output += &self.print_value(inner, indent + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Value::Seq(seq) => {
|
|
||||||
if seq.is_empty() {
|
|
||||||
output += &format!("{}[]\n", pad);
|
|
||||||
} else {
|
|
||||||
output += &format!("{}[\n", pad);
|
|
||||||
for item in seq {
|
|
||||||
output += &self.print_value(item, indent + 1);
|
|
||||||
}
|
|
||||||
output += &format!("{}]\n", pad);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Value::Map(map) => {
|
|
||||||
if map.is_empty() {
|
|
||||||
output += &format!("{}<empty map>\n", pad);
|
|
||||||
} else {
|
|
||||||
output += &format!(
|
|
||||||
"\n{}+--------------------------+----------------------------+\n",
|
|
||||||
pad
|
|
||||||
);
|
|
||||||
output += &format!(
|
|
||||||
"{}| {:<24} | {:<26} |\n",
|
|
||||||
pad, "Key", "Value"
|
|
||||||
);
|
|
||||||
output += &format!(
|
|
||||||
"{}+--------------------------+----------------------------+\n",
|
|
||||||
pad
|
|
||||||
);
|
|
||||||
|
|
||||||
for (k, v) in map {
|
|
||||||
let key_str = match k {
|
|
||||||
Value::String(s) => s.clone(),
|
|
||||||
other => format!("{:?}", other),
|
|
||||||
};
|
|
||||||
let val_str = match v {
|
|
||||||
Value::String(s) => s.clone(),
|
|
||||||
Value::Bool(b) => b.to_string(),
|
|
||||||
Value::Option(Some(inner)) => format!("{:?}", inner),
|
|
||||||
Value::Option(None) => "None".to_string(),
|
|
||||||
Value::Seq(seq) => format!("{:?}", seq),
|
|
||||||
_ => format!("{:?}", v),
|
|
||||||
};
|
|
||||||
|
|
||||||
output += &format!(
|
|
||||||
"{}| {:<24} | {:<26} |\n",
|
|
||||||
pad, key_str, val_str
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
output += &format!(
|
|
||||||
"{}+--------------------------+----------------------------+\n\n",
|
|
||||||
pad
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
output
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn display_value(&self) -> String {
|
|
||||||
let mut output = String::new();
|
|
||||||
output += "SCORE DETAILS";
|
|
||||||
for score in &self.scores {
|
|
||||||
let val = score.serialize();
|
|
||||||
output += &self.print_value(&val, 0);
|
|
||||||
}
|
|
||||||
output
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn scroll_down(&self) {
|
pub(crate) fn scroll_down(&self) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user