1
0
mirror of https://github.com/sharkdp/bat synced 2026-08-09 19:51:48 +00:00

Adds range syntax for line highlights

This commit is contained in:
Liam Kalir
2020-01-22 22:26:21 -05:00
committed by David Peter
parent 87776ae07e
commit 93881d9a64
5 changed files with 40 additions and 23 deletions
+7 -5
View File
@@ -215,11 +215,13 @@ impl App {
Some("always") => true,
_ => false,
},
highlight_lines: self
.matches
.values_of("highlight-line")
.and_then(|ws| ws.map(|w| w.parse().ok()).collect())
.unwrap_or_default(),
highlight_lines: LineRanges::from(
self.matches
.values_of("highlight-line")
.map(|ws| ws.map(LineRange::from).collect())
.transpose()?
.unwrap_or_else(|| vec![LineRange { lower: 0, upper: 0 }]),
),
})
}
+10 -4
View File
@@ -82,10 +82,15 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
.takes_value(true)
.number_of_values(1)
.multiple(true)
.value_name("N")
.help("Highlight the given line.")
.value_name("N:M")
.help("Highlight lines N through M.")
.long_help(
"Highlight the N-th line with a different background color",
"Highlight the specified line ranges with a different background color \
For example:\n \
'--highlight-line 30:40' highlights lines 30 to 40\n \
'--highlight-line :40' highlights lines 1 to 40\n \
'--highlight-line 40:' highlights lines 40 to the end of the file\n \
'--highlight-line 40' highlights only line 40",
),
)
.arg(
@@ -328,7 +333,8 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
For example:\n \
'--line-range 30:40' prints lines 30 to 40\n \
'--line-range :40' prints lines 1 to 40\n \
'--line-range 40:' prints lines 40 to the end of the file",
'--line-range 40:' prints lines 40 to the end of the file\n \
'--line-range 40' prints only line 40",
),
)
.arg(