Improve value display
This commit is contained in:
parent
a6a02f26e4
commit
dac7656572
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -204,6 +204,7 @@ dependencies = [
|
||||
"clap",
|
||||
"colored",
|
||||
"env_logger",
|
||||
"stanza",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -404,6 +405,12 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "stanza"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d230b987a5b524a015ded47fed54c5177598a71c90508acee1c5d0b4c955f74"
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.11.0"
|
||||
|
@ -18,3 +18,4 @@ chumsky = { version = "1.0.0-alpha.6", features = ["pratt", "label"] }
|
||||
clap = { version = "4.5.2", features = ["derive"] }
|
||||
colored = "2.1.0"
|
||||
env_logger = "0.11.3"
|
||||
stanza = "0.5.1"
|
||||
|
31
src/value.rs
31
src/value.rs
@ -6,6 +6,12 @@ use std::{
|
||||
sync::{Arc, OnceLock},
|
||||
};
|
||||
|
||||
use stanza::{
|
||||
renderer::{console::Console, Renderer},
|
||||
style::{HAlign, MinWidth, Styles},
|
||||
table::Table,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
abstract_tree::{Identifier, Type},
|
||||
error::ValidationError,
|
||||
@ -128,22 +134,35 @@ impl Display for Value {
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
use ValueInner::*;
|
||||
|
||||
fn create_table() -> Table {
|
||||
Table::with_styles(Styles::default().with(HAlign::Centred).with(MinWidth(3)))
|
||||
}
|
||||
|
||||
match self.inner().as_ref() {
|
||||
Boolean(boolean) => write!(f, "{boolean}"),
|
||||
Float(float) => write!(f, "{float}"),
|
||||
Integer(integer) => write!(f, "{integer}"),
|
||||
List(_) => todo!(),
|
||||
Map(map) => {
|
||||
writeln!(f, "{{")?;
|
||||
List(list) => {
|
||||
let mut table = create_table();
|
||||
|
||||
for (identifier, value) in map {
|
||||
writeln!(f, " {identifier} = {value}")?;
|
||||
for value in list {
|
||||
table = table.with_row([value.to_string()]);
|
||||
}
|
||||
|
||||
write!(f, "}}")
|
||||
write!(f, "{}", Console::default().render(&table))
|
||||
}
|
||||
Map(map) => {
|
||||
let mut table = create_table();
|
||||
|
||||
for (identifier, value) in map {
|
||||
table = table.with_row([identifier.as_str(), &value.to_string()]);
|
||||
}
|
||||
|
||||
write!(f, "{}", Console::default().render(&table))
|
||||
}
|
||||
Range(_) => todo!(),
|
||||
String(string) => write!(f, "{string}"),
|
||||
|
||||
Enum(_, _) => todo!(),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user