diff options
author | Mahdi Dibaiee <mdibaiee@pm.me> | 2022-02-14 18:02:14 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-14 19:02:14 +0100 |
commit | d21f1e8f1792297510c32f661ab9bf2e94da9219 (patch) | |
tree | 71abe2f5a764497fdc9ad5b81a3a216d9d56d80b | |
parent | f6ce5d2054cc7ac2d556358e5b87370bd66b2bc8 (diff) |
Underline highlighted lines in ANSI theme (#1985)
* Underline highlighted lines in ANSI theme
* add test for ansi highlight underline, fix underscore in plain
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | src/printer.rs | 9 | ||||
-rw-r--r-- | tests/integration_tests.rs | 19 |
3 files changed, 29 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index eb5a07d5..01facab0 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 2c70421d..ad041e03 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,11 @@ impl<'a> Printer for InteractivePrinter<'a> { writeln!(handle)?; } + 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 a4224c94..65da610a 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() { |