Repository: sharkdp/bat (language: rust)

Issue:
Add lineHighlight for ansi theme
The ansi theme doesn't have `lineHighlight` defined, so the highlighted line is not apparent.


Discussion / hints:
Thank you for reporting this! Should be easy to fix, I hope.
Well what I realized is that no single color will work well, depending on whether a user has a light or dark background. I imagine this is part of why there were once separate ansi-dark and ansi-light themes.
FYI @mk12: again, only if you are interested(!).
Can you share an example of when bat would use this? I'm not sure when a line would be highlighted.
Ah, yes. Sorry. Whenever someone uses the `--highlight-line` option:
```
    -H, --highlight-line <N:M>...        Highlight lines N through M.
```

For example:
```
seq 10 | bat --highlight-line 3:5
```

![image](https://user-images.githubusercontent.com/4209276/126942481-63bf35f4-0f72-4faf-8bf9-b4025544cbce.png)

Thanks for the example, I didn't know about that.

Even if `ansi-light` and `ansi-dark` were still separate I don't think there's any good color for this in a typical 8 color palette. For example if you choose yellow then foreground yellow text becomes invisible. You could choose from the 256-color palette but that defeats the purpose of `ansi` being restricted to the 8 color palette.

I'd suggest using bold (already supported I believe) or reverse video (would need to use another alpha channel pattern to encode it). What do you think?
What's the support for underline like? I imagine it's less common in terminal emulator than bold.
> What's the support for underline like? I imagine it's less common in terminal emulator than bold.

Yes, definitely.

Let's try this out.

Fix patch:
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..ad041e03d7 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(())
     }
 }


Test patch:
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() {