sharkdp / bat

A cat(1) clone with wings.
Apache License 2.0
48.68k stars 1.23k forks source link

Text indicators of highlighted lines #1324

Open cpkio opened 3 years ago

cpkio commented 3 years ago

For --color=never line highlighting is not working because of no color codes. A text indicator prepended to highlighted lines with an option to set this indicator could be helpful.

  30 - Added `--preview-window` option for sharp edges (`--preview-window sharp`)
> 31 - Added `--preview-window` option for cyclic scrolling (`--preview-window cycle`)
> 32 - Reduced vertical padding around the preview window when `--preview-window
> 33   noborder` is used
  34 - Added actions for preview window
  35     - `preview-half-page-up`
  36     - `preview-half-page-down`

or

  30 - Added `--preview-window` option for sharp edges (`--preview-window sharp`)
| 31 - Added `--preview-window` option for cyclic scrolling (`--preview-window cycle`)
| 32 - Reduced vertical padding around the preview window when `--preview-window
| 33   noborder` is used
  34 - Added actions for preview window
  35     - `preview-half-page-up`
  36     - `preview-half-page-down`
eth-p commented 3 years ago

I like this idea. When using batgrep with color, it's sometimes even hard to see which line was the matched one.

Maybe we could add it as a new component highlight-indicator that shows regardless of color settings?

sharkdp commented 3 years ago

Thank you for the feedback.

I also like the idea, but it would require us to increase the horizontal size of the sidebar, right?

Or could we find a nice way to modify the vertical border? Something like

  80   │ [build-dependencies]
  81   │ clap = { version = "2.33", optional = true }
  82 + ┝╸new line
  83   ┝╸
  84   ┝╸[profile.release]
  85 ~ ┝╸modified line
  86   │ codegen-units = 1

image

which actually looks good? :smile: (https://en.wikipedia.org/wiki/Box-drawing_character)

Maybe we could add it as a new component highlight-indicator that shows regardless of color settings?

Alternatively, depending on how subtle it would be, it could be part of the "grid" style component and only show up if the grid is enabled.

cpkio commented 3 years ago

The fancy border drawing characters are not part of every monospaced font, so using them would limit usability of this feature. I suggest using most common characters.

stku1985 commented 3 years ago

This is actually implemented, isn't it?

❯ bat --diff src/printer.rs --color=never
...
 334   │         }
 335   │     }
 336 ~ │ unsafe as
 337 ~ │     unsafe // tag::s[]
 338 ~ │     f
 339 ~ │     // end::s[]
 340   │     fn print_snip(&mut self, handle: &mut dyn Write) -> Result<()> {
 341   │         let panel = self.create_fake_panel(" ...");
...
sharkdp commented 3 years ago

For Git modifications, yes. But not for highlighted lines.

cpkio commented 1 year ago

Any progress on this?

sharkdp commented 1 year ago

no