1
0
mirror of https://github.com/sharkdp/bat synced 2026-08-02 18:41:42 +00:00

Feature: Highlight non-printable characters

Adds a new `-A`/`--show-all` option (in analogy to GNU Linux `cat`s option) that
highlights non-printable characters like space, tab or newline.

This works in two steps:
- **Preprocessing**: replace space by `•`, replace tab by `├──┤`, replace
newline by `␤`, etc.
- **Highlighting**: Use a newly written Sublime syntax to highlight
these special symbols.

Note: This feature is not technically a drop-in replacement for GNU `cat`s
`--show-all` but it has the same purpose.
This commit is contained in:
sharkdp
2018-11-01 13:02:29 +01:00
committed by David Peter
parent cbed338c3a
commit ecd862d9ff
6 changed files with 108 additions and 5 deletions
+11 -1
View File
@@ -37,6 +37,9 @@ pub struct Config<'a> {
/// The explicitly configured language, if any
pub language: Option<&'a str>,
/// Whether or not to show/replace non-printable characters like space, tab and newline.
pub show_nonprintable: bool,
/// The character width of the terminal
pub term_width: usize,
@@ -169,7 +172,14 @@ impl App {
Ok(Config {
true_color: is_truecolor_terminal(),
language: self.matches.value_of("language"),
language: self.matches.value_of("language").or_else(|| {
if self.matches.is_present("show-all") {
Some("show-nonprintable")
} else {
None
}
}),
show_nonprintable: self.matches.is_present("show-all"),
output_wrap: if !self.interactive_output {
// We don't have the tty width when piping to another program.
// There's no point in wrapping when this is the case.