Skip to content

Commit c2a724a

Browse files
committed
syntax-highlight example config
1 parent e7a6f71 commit c2a724a

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ documented = "0.8.0"
1515
futures = "0.3.30"
1616
gitlab = "0.1705.0"
1717
http = "1.1.0"
18+
inkjet = { version = "0.11.1", features = ["language-toml", "theme", "terminal"] }
1819
itertools = "0.13.0"
1920
log = "0.4.22"
2021
serde = "1.0.210"
@@ -23,6 +24,7 @@ serde_json = "1.0.128"
2324
shellexpand = "3.1.0"
2425
simple_logger = { version = "5.0.0", features = ["stderr"] }
2526
struct-field-names-as-array = "0.3.0"
27+
termcolor = "1.4.1"
2628
tokio = { version = "1.40.0", features = ["full"] }
2729
tokio-util = "0.7.12"
2830
toml = "0.8.19"

src/config.rs

+19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
use anyhow::Context;
22
use documented::DocumentedFields;
3+
use inkjet::{
4+
formatter::Terminal,
5+
theme::{vendored, Theme},
6+
Highlighter, Language,
7+
};
38
use itertools::Itertools;
49
use log::warn;
510
use std::{
@@ -9,6 +14,7 @@ use std::{
914
path::{Path, PathBuf},
1015
};
1116
use struct_field_names_as_array::FieldNamesAsArray;
17+
use termcolor::{ColorChoice, StandardStream};
1218
use toml_edit::{DocumentMut, RawString};
1319

1420
use serde::{de::Error, Deserializer, Serializer};
@@ -358,6 +364,19 @@ pub fn get_example_config_str() -> String {
358364
document.to_string()
359365
}
360366

367+
pub fn print_example_config_highlighted() {
368+
let config = get_example_config_str();
369+
let mut highlighter = Highlighter::new();
370+
let language = Language::Toml;
371+
let theme: Theme = Theme::from_helix(vendored::BASE16_TERMINAL).unwrap();
372+
let stream = StandardStream::stdout(ColorChoice::Auto);
373+
let formatter = Terminal::new(theme, stream);
374+
highlighter
375+
.highlight_to_writer(language, &formatter, &config, &mut std::io::sink())
376+
.unwrap();
377+
println!();
378+
}
379+
361380
pub fn write_example_config(filename: &Path) -> anyhow::Result<()> {
362381
let mut file = std::fs::File::create_new(filename)
363382
.context(format!("Failed creating config file {:?}", filename))?;

src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn main() -> anyhow::Result<()> {
2727
.unwrap();
2828
match cli.command {
2929
cli::Command::CreateExampleConfig => config::write_example_config(&cli.paths.config_file),
30-
cli::Command::ShowExampleConfig => Ok(println!("{}", config::get_default_config_str())),
30+
cli::Command::ShowExampleConfig => Ok(config::print_example_config_highlighted()),
3131
cli::Command::CheckConfig => check_config::check(&cli.paths),
3232
cli::Command::ShowConfig => check_config::show(&cli.paths),
3333
cli::Command::Configure => configure::configure(&cli.paths),

0 commit comments

Comments
 (0)