mirror of
https://github.com/sharkdp/bat.git
synced 2026-10-30 10:06:12 +00:00
feat: implement -b / --number-nonblank for cat -b compatibility
Adds a `-b` / `--number-nonblank` flag that numbers only non-blank lines. Blank lines (those containing only the line terminator) are printed without a number and don't advance the counter, matching `cat -b` behaviour. - `-b` implies `--style=numbers` (same as `-n`), but only counts non-blank lines - `-b` takes precedence over `-n`: both `-bn` and `-nb` behave like `-b` - `-bp` disables numbering (plain mode wins) - Works with files, stdin, and piped output (like `-n`) Closes #3856.
This commit is contained in:
1 parent
78951393e2
commit
061fb216cb
10 files changed
+168
-6
No files matched your search
+8
-1
@@ -738,10 +738,17 @@ impl Printer for InteractivePrinter<'_> {
|
||||
|
||||
// Line decorations.
|
||||
if self.panel_width > 0 {
|
||||
let display_line_number =
|
||||
if self.config.number_nonblank && line.trim_end_matches(['\r', '\n']).is_empty() {
|
||||
0
|
||||
} else {
|
||||
line_number
|
||||
};
|
||||
|
||||
let decorations = self
|
||||
.decorations
|
||||
.iter()
|
||||
.map(|d| d.generate(line_number, false, self));
|
||||
.map(|d| d.generate(display_line_number, false, self));
|
||||
|
||||
for deco in decorations {
|
||||
write!(handle, "{} ", deco.text)?;
|
||||
|
||||
Reference in new issue
Block a user