modified tui-example main
This commit is contained in:
@@ -1,18 +1,22 @@
|
||||
use ratatui::layout::Constraint;
|
||||
use serde_value::Value;
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
use crate::HarmonyTuiEvent;
|
||||
use crossterm::event::{Event, KeyCode, KeyEventKind};
|
||||
use harmony::{score::Score, topology::Topology};
|
||||
use log::{info, warn};
|
||||
use ratatui::{
|
||||
Frame,
|
||||
layout::Rect,
|
||||
style::{Style, Stylize},
|
||||
widgets::{List, ListItem, ListState, StatefulWidget, Widget},
|
||||
style::{Modifier, Style, Stylize},
|
||||
widgets::{
|
||||
Block, Borders, Cell, List, ListItem, ListState, Row, StatefulWidget, Table, Widget,
|
||||
},
|
||||
};
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
use crate::HarmonyTuiEvent;
|
||||
|
||||
#[derive(Debug)]
|
||||
enum ExecutionState {
|
||||
INITIATED,
|
||||
@@ -64,11 +68,126 @@ impl<T: Topology + std::fmt::Debug> ScoreListWidget<T> {
|
||||
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);
|
||||
} 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);
|
||||
}
|
||||
|
||||
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) {
|
||||
self.list_state.write().unwrap().scroll_down_by(1);
|
||||
|
||||
Reference in New Issue
Block a user