Skip to content

Commit c6ea17f

Browse files
committed
Customize gpptool output color
1 parent 3638260 commit c6ea17f

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

gpptool/src/main.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clap::{Parser, Subcommand};
2-
use colored_json::ToColoredJson;
2+
use colored_json::{Color, ColorMode, Output, Styler, ToColoredJson};
33
use iab_gpp::sections::SectionId;
44
use iab_gpp::v1::GPPString;
55
use num_traits::cast::FromPrimitive;
@@ -61,7 +61,8 @@ fn parse_gpp_string(s: &str) -> Result<(), Box<dyn std::error::Error>> {
6161

6262
println!(
6363
"{}",
64-
serde_json::to_string_pretty(&sections)?.to_colored_json_auto()?
64+
serde_json::to_string_pretty(&sections)?
65+
.to_colored_json_with_styler(ColorMode::Auto(Output::StdOut), json_color_styler())?
6566
);
6667

6768
Ok(())
@@ -74,7 +75,8 @@ fn parse_gpp_string_section(s: &str, id: u32) -> Result<(), Box<dyn std::error::
7475

7576
println!(
7677
"{}",
77-
serde_json::to_string_pretty(&section)?.to_colored_json_auto()?
78+
serde_json::to_string_pretty(&section)?
79+
.to_colored_json_with_styler(ColorMode::Auto(Output::StdOut), json_color_styler())?
7880
);
7981

8082
Ok(())
@@ -89,3 +91,15 @@ fn list_sections(s: &str) -> Result<(), Box<dyn std::error::Error>> {
8991

9092
Ok(())
9193
}
94+
95+
fn json_color_styler() -> Styler {
96+
Styler {
97+
key: Color::Green.foreground(),
98+
string_value: Color::Blue.bold(),
99+
integer_value: Color::Magenta.bold(),
100+
float_value: Color::Magenta.italic(),
101+
object_brackets: Color::Yellow.bold(),
102+
array_brackets: Color::Cyan.bold(),
103+
..Default::default()
104+
}
105+
}

0 commit comments

Comments
 (0)