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