Compare commits

...

6 Commits

Author SHA1 Message Date
Dipesh Kafle 8e056c2440
Merge 0749f8c3d2 into b4e3a84e1a 2024-05-01 05:26:28 +01:00
dependabot[bot] b4e3a84e1a
Bump serde from 1.0.197 to 1.0.199 (#2953)
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.197 to 1.0.199.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.197...v1.0.199)

---
updated-dependencies:
- dependency-name: serde
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-05-01 03:23:25 +00:00
dependabot[bot] f7c39e8353
Bump os_str_bytes from 6.6.1 to 7.0.0 (#2952)
Bumps [os_str_bytes](https://github.com/dylni/os_str_bytes) from 6.6.1 to 7.0.0.
- [Release notes](https://github.com/dylni/os_str_bytes/releases)
- [Commits](https://github.com/dylni/os_str_bytes/compare/6.6.1...7.0.0)

---
updated-dependencies:
- dependency-name: os_str_bytes
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-05-01 03:10:09 +00:00
dependabot[bot] 37d9f0533c
Bump indexmap from 2.2.2 to 2.2.6 (#2950)
Bumps [indexmap](https://github.com/indexmap-rs/indexmap) from 2.2.2 to 2.2.6.
- [Changelog](https://github.com/indexmap-rs/indexmap/blob/master/RELEASES.md)
- [Commits](https://github.com/indexmap-rs/indexmap/compare/2.2.2...2.2.6)

---
updated-dependencies:
- dependency-name: indexmap
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-05-01 02:47:11 +00:00
dependabot[bot] d560f2a515
Bump serde_with from 3.7.0 to 3.8.1 (#2949)
Bumps [serde_with](https://github.com/jonasbb/serde_with) from 3.7.0 to 3.8.1.
- [Release notes](https://github.com/jonasbb/serde_with/releases)
- [Commits](https://github.com/jonasbb/serde_with/compare/v3.7.0...v3.8.1)

---
updated-dependencies:
- dependency-name: serde_with
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-05-01 02:27:04 +00:00
Dipesh Kafle 0749f8c3d2 Add context-around-highlight 2023-11-22 23:36:13 +05:30
5 changed files with 65 additions and 20 deletions

24
Cargo.lock generated
View File

@ -647,9 +647,9 @@ dependencies = [
[[package]]
name = "indexmap"
version = "2.2.2"
version = "2.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "824b2ae422412366ba479e8111fd301f7b5faece8149317bb81925979a53f520"
checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26"
dependencies = [
"equivalent",
"hashbrown 0.14.1",
@ -839,9 +839,9 @@ dependencies = [
[[package]]
name = "os_str_bytes"
version = "6.6.1"
version = "7.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1"
checksum = "7ac44c994af577c799b1b4bd80dc214701e349873ad894d6cdf96f4f7526e0b9"
dependencies = [
"memchr",
]
@ -1116,18 +1116,18 @@ checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0"
[[package]]
name = "serde"
version = "1.0.197"
version = "1.0.199"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2"
checksum = "0c9f6e76df036c77cd94996771fb40db98187f096dd0b9af39c6c6e452ba966a"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.197"
version = "1.0.199"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
checksum = "11bd257a6541e141e42ca6d24ae26f7714887b47e89aa739099104c7e4d3b7fc"
dependencies = [
"proc-macro2",
"quote",
@ -1156,9 +1156,9 @@ dependencies = [
[[package]]
name = "serde_with"
version = "3.7.0"
version = "3.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee80b0e361bbf88fd2f6e242ccd19cfda072cb0faa6ae694ecee08199938569a"
checksum = "0ad483d2ab0149d5a5ebcd9972a3852711e0153d863bf5a5d0391d28883c4a20"
dependencies = [
"serde",
"serde_derive",
@ -1167,9 +1167,9 @@ dependencies = [
[[package]]
name = "serde_with_macros"
version = "3.7.0"
version = "3.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6561dc161a9224638a31d876ccdfefbc1df91d3f3a8342eddb35f055d48c7655"
checksum = "65569b702f41443e8bc8bbb1c5779bd0450bbe723b56198980e80ec45780bce2"
dependencies = [
"darling",
"proc-macro2",

View File

@ -66,7 +66,7 @@ regex = { version = "1.10.2", optional = true }
walkdir = { version = "2.4", optional = true }
bytesize = { version = "1.3.0" }
encoding_rs = "0.8.33"
os_str_bytes = { version = "~6.6", optional = true }
os_str_bytes = { version = "~7.0", optional = true }
run_script = { version = "^0.10.1", optional = true}
[dependencies.git2]
@ -102,13 +102,13 @@ nix = { version = "0.26.4", default-features = false, features = ["term"] }
[build-dependencies]
anyhow = "1.0.78"
indexmap = { version = "2.2.2", features = ["serde"] }
indexmap = { version = "2.2.6", features = ["serde"] }
itertools = "0.12.1"
once_cell = "1.18"
regex = "1.10.2"
serde = "1.0"
serde_derive = "1.0"
serde_with = { version = "3.7.0", default-features = false, features = ["macros"] }
serde_with = { version = "3.8.1", default-features = false, features = ["macros"] }
toml = { version = "0.8.9", features = ["preserve_order"] }
walkdir = "2.4"

View File

@ -7,6 +7,7 @@ use crate::{
clap_app,
config::{get_args_from_config_file, get_args_from_env_opts_var, get_args_from_env_vars},
};
use bat::line_range;
use clap::ArgMatches;
use console::Term;
@ -265,14 +266,42 @@ impl App {
.unwrap_or(2),
),
_ => VisibleLines::Ranges(
self.matches
_ => VisibleLines::Ranges({
let line_range = self
.matches
.get_many::<String>("line-range")
.map(|vs| vs.map(|s| LineRange::from(s.as_str())).collect())
.transpose()?
.map(LineRanges::from)
.unwrap_or_default(),
),
.map(LineRanges::from);
let context = self
.matches
.get_one::<String>("context-around-highlight")
.and_then(|s| usize::from_str_radix(s, 10).ok())
.unwrap_or_else(|| 0);
let range_due_to_highlighted_lines = self
.matches
.get_many::<String>("highlight-line")
.map(|ws| {
ws.map(|s| {
let lr = LineRange::from(s.as_str());
lr.map(|line_range| {
LineRange::new(
line_range.get_lower().saturating_sub(context),
line_range.get_upper().saturating_add(context),
)
})
})
.collect()
})
.transpose()?
.map(LineRanges::from);
match ( line_range, range_due_to_highlighted_lines ) {
( Some(range), None ) | ( None, Some(range) ) => range,
( None, None ) => LineRanges::default(),
_ => unreachable!("line-range and context-around-highlight are conflicting, so this is impossible")
}
}),
},
style_components,
syntax_mapping,

View File

@ -120,6 +120,16 @@ pub fn build_app(interactive_output: bool) -> Command {
'--highlight-line 30:+10' highlights lines 30 to 40",
),
)
.arg(
Arg::new("context-around-highlight")
.long("context-around-highlight")
.action(ArgAction::Set)
.requires("highlight-line")
.conflicts_with("line-range")
.conflicts_with("diff")
.value_name("N")
.help("Show lines from highlighted line - N through highlighted line + N"),
)
.arg(
Arg::new("file-name")
.long("file-name")

View File

@ -77,6 +77,12 @@ impl LineRange {
),
}
}
pub fn get_lower(&self) -> usize {
self.lower
}
pub fn get_upper(&self) -> usize {
self.upper
}
pub(crate) fn is_inside(&self, line: usize) -> bool {
line >= self.lower && line <= self.upper