From 6f28c90794c52aa9e604968b071c7276ddeda88a Mon Sep 17 00:00:00 2001 From: Mahdi Dibaiee Date: Thu, 23 Dec 2021 23:29:32 +0000 Subject: [PATCH 1/2] Underline highlighted lines in ANSI theme --- CHANGELOG.md | 1 + src/printer.rs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae73464145..80915c5752 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Features - New style component `header-filesize` to show size of the displayed file in the header. See #1988 (@mdibaiee) +- Use underline for line highlighting on ANSI, see #1730 (@mdibaiee) ## Bugfixes diff --git a/src/printer.rs b/src/printer.rs index 2c70421d14..c28a8ae643 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -463,6 +463,10 @@ impl<'a> Printer for InteractivePrinter<'a> { let highlight_this_line = self.config.highlighted_lines.0.check(line_number) == RangeCheckResult::InRange; + if highlight_this_line && self.config.theme == "ansi" { + self.ansi_style.update("^[4m"); + } + let background_color = self .background_color_highlight .filter(|_| highlight_this_line); @@ -649,6 +653,10 @@ impl<'a> Printer for InteractivePrinter<'a> { writeln!(handle)?; } + if highlight_this_line && self.config.theme == "ansi" { + self.ansi_style.update("^[24m"); + } + Ok(()) } } From 433b8b739a330107f6083f3ee70f5473ac3f34d0 Mon Sep 17 00:00:00 2001 From: Mahdi Dibaiee Date: Mon, 7 Feb 2022 21:48:48 +0000 Subject: [PATCH 2/2] add test for ansi highlight underline, fix underscore in plain --- src/printer.rs | 1 + tests/integration_tests.rs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/printer.rs b/src/printer.rs index c28a8ae643..ad041e03d7 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -655,6 +655,7 @@ impl<'a> Printer for InteractivePrinter<'a> { if highlight_this_line && self.config.theme == "ansi" { self.ansi_style.update("^[24m"); + write!(handle, "\x1B[24m")?; } Ok(()) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index a4224c9463..65da610a6c 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -1290,6 +1290,25 @@ fn grid_for_file_without_newline() { .stderr(""); } +// For ANSI theme, use underscore as a highlighter +#[test] +fn ansi_highlight_underline() { + bat() + .arg("--paging=never") + .arg("--color=never") + .arg("--terminal-width=80") + .arg("--wrap=never") + .arg("--decorations=always") + .arg("--theme=ansi") + .arg("--style=plain") + .arg("--highlight-line=1") + .write_stdin("Ansi Underscore Test\nAnother Line") + .assert() + .success() + .stdout("\x1B[4mAnsi Underscore Test\n\x1B[24mAnother Line") + .stderr(""); +} + // Ensure that ANSI passthrough is emitted properly for both wrapping and non-wrapping printer. #[test] fn ansi_passthrough_emit() {