diff --git a/src/cli.rs b/src/cli.rs index 3df16bd..d461a3e 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -86,10 +86,6 @@ pub(crate) struct Cli { #[arg(short = 'r', long = "raw", requires = "command_or_file")] pub raw: bool, - /// Display output without indentation - #[arg(short = 'C', long = "compact", requires = "command_or_file")] - pub compact: bool, - /// Suppress informational messages #[arg(short = 'q', long = "quiet")] pub quiet: bool, diff --git a/src/config.rs b/src/config.rs index 2c39235..5e6b48f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -171,6 +171,8 @@ struct RawDisplayConfig { pub use_pager: bool, #[serde(default)] pub show_title: bool, + #[serde(default)] + pub indent: usize, } impl From<&RawDisplayConfig> for DisplayConfig { @@ -179,6 +181,7 @@ impl From<&RawDisplayConfig> for DisplayConfig { compact: raw_display_config.compact, use_pager: raw_display_config.use_pager, show_title: raw_display_config.show_title, + indent: raw_display_config.indent, } } } @@ -312,6 +315,7 @@ impl Default for RawConfig { raw_config.style.example_code.foreground = Some(RawColor::Cyan); raw_config.style.example_variable.foreground = Some(RawColor::Cyan); raw_config.style.example_variable.underline = true; + raw_config.display.indent = 6; raw_config } @@ -331,6 +335,7 @@ pub struct DisplayConfig { pub compact: bool, pub use_pager: bool, pub show_title: bool, + pub indent: usize, } #[derive(Clone, Debug, PartialEq, Eq)] diff --git a/src/formatter.rs b/src/formatter.rs index 9df57cb..50442ce 100644 --- a/src/formatter.rs +++ b/src/formatter.rs @@ -68,7 +68,7 @@ pub fn highlight_lines( process_snippet: &mut F, keep_empty_lines: bool, show_title: bool, - compact: bool, + indent: usize, ) -> Result<(), E> where L: Iterator, @@ -97,9 +97,8 @@ where LineType::Description(text) => process_snippet(PageSnippet::Description(&text))?, LineType::ExampleText(text) => process_snippet(PageSnippet::Text(&text))?, LineType::ExampleCode(text) => { - if !compact { - process_snippet(PageSnippet::NormalCode(" "))?; - } + let spaces = " ".repeat(indent); + process_snippet(PageSnippet::NormalCode(&spaces))?; highlight_code(&command, &text, process_snippet)?; process_snippet(PageSnippet::Linebreak)?; } diff --git a/src/main.rs b/src/main.rs index 871c693..1d1b5fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -259,14 +259,7 @@ fn try_main(args: Cli, enable_styles: bool) -> Result { // If a local file was passed in, render it and exit if let Some(file) = args.render { let path = PageLookupResult::with_page(file); - print_page( - &path, - args.raw, - enable_styles, - args.pager, - args.compact, - &config, - )?; + print_page(&path, args.raw, enable_styles, args.pager, &config)?; return Ok(ExitCode::SUCCESS); } @@ -430,14 +423,7 @@ fn try_main(args: Cli, enable_styles: bool) -> Result { return Ok(ExitCode::FAILURE); }; - print_page( - &lookup_result, - args.raw, - enable_styles, - args.pager, - args.compact, - &config, - )?; + print_page(&lookup_result, args.raw, enable_styles, args.pager, &config)?; } Ok(ExitCode::SUCCESS) diff --git a/src/output.rs b/src/output.rs index 8f6b1b3..7ea56d2 100644 --- a/src/output.rs +++ b/src/output.rs @@ -34,7 +34,6 @@ pub fn print_page( enable_markdown: bool, enable_styles: bool, use_pager: bool, - compact: bool, config: &Config, ) -> Result<()> { // Create reader from file(s) @@ -61,8 +60,7 @@ pub fn print_page( if snip.is_empty() { Ok(()) } else { - print_snippet(&mut handle, snip, &config.style, compact) - .context("Failed to print snippet") + print_snippet(&mut handle, snip, &config.style).context("Failed to print snippet") } }; @@ -72,7 +70,7 @@ pub fn print_page( &mut process_snippet, !config.display.compact, config.display.show_title, - compact, + config.display.indent, ) .context("Could not write to stdout")?; } @@ -87,18 +85,15 @@ fn print_snippet( writer: &mut impl Write, snip: PageSnippet<&str>, style: &StyleConfig, - compact: bool, ) -> io::Result<()> { use PageSnippet::*; - let indent = if compact { "" } else { " " }; - match snip { CommandName(s) => write!(writer, "{}", s.paint(style.command_name)), Variable(s) => write!(writer, "{}", s.paint(style.example_variable)), NormalCode(s) => write!(writer, "{}", s.paint(style.example_code)), - Description(s) => writeln!(writer, "{}{}", indent, s.paint(style.description)), - Text(s) => writeln!(writer, "{}{}", indent, s.paint(style.example_text)), + Description(s) => writeln!(writer, " {}", s.paint(style.description)), + Text(s) => writeln!(writer, " {}", s.paint(style.example_text)), Title(s) => writeln!(writer, " {}", s.paint(style.command_name)), Linebreak => writeln!(writer), } diff --git a/tests/lib.rs b/tests/lib.rs index 253677c..652a17d 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -811,14 +811,21 @@ fn test_rendering_color_never() { ); } -/// An end-to-end integration test for the `--compact` flag (no indentation on description/text lines). +/// An end-to-end integration test for the indent config option #[test] -fn test_rendering_compact() { - _test_correct_rendering( - "inkscape-v2", - include_str!("rendered/inkscape-compact-no-color.expected"), - &["--color", "never", "--compact"], - ); +fn test_rendering_with_indentation() { + let testenv = TestEnv::new().install_default_cache(); + let expected_custom_indentation = include_str!("rendered/inkscape-compact-no-color.expected"); + + // Configure to set indent to 2 spaces + testenv.append_to_config("display.indent = 2\n"); + + testenv + .command() + .args(["--color", "never", "inkscape-v2"]) + .assert() + .success() + .stdout(diff(expected_custom_indentation)); } #[test] @@ -852,6 +859,7 @@ fn test_correct_rendering_with_config() { fn test_show_title_config() { // Test that default behavior without show_title shows no title let testenv = TestEnv::new().install_default_cache(); + testenv.append_to_config("display.indent = 6\n"); let expected_no_title = include_str!("rendered/inkscape-default.expected"); testenv