wip:made score details box output information for highlighted score, worked on outputing score info in log output

This commit is contained in:
2025-04-11 15:16:33 -04:00
parent 6ddf48591b
commit 4f8523ab69
3 changed files with 126 additions and 132 deletions

View File

@@ -1,6 +1,3 @@
use ratatui::layout::Constraint;
use serde_value::Value;
use std::collections::BTreeMap;
use std::sync::{Arc, RwLock};
use crate::HarmonyTuiEvent;
@@ -10,10 +7,8 @@ use log::{info, warn};
use ratatui::{
Frame,
layout::Rect,
style::{Modifier, Style, Stylize},
widgets::{
Block, Borders, Cell, List, ListItem, ListState, Row, StatefulWidget, Table, Widget,
},
style::{Style, Stylize},
widgets::{List, ListItem, ListState, StatefulWidget, Widget},
};
use tokio::sync::mpsc;
@@ -57,136 +52,25 @@ 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(),
});
//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!("{:#?}", score.display_value());
} else {
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
//and output them by calling fn display_values in the about fn
//
//currently outputs info about all available scores, not quite
//looking to output info about the selected score and subscores
//
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);
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
}
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) {