mirror of
https://github.com/sharkdp/bat
synced 2026-08-06 19:21:43 +00:00
Merge pull request #3812 from greymoth-jp/fix/list-languages-narrow-width-underflow
fix: avoid usize underflow in --list-languages at narrow terminal width
This commit is contained in:
@@ -46,6 +46,7 @@
|
|||||||
- Fixed syntax tests path, see #3610 (@foxfromworld)
|
- Fixed syntax tests path, see #3610 (@foxfromworld)
|
||||||
- Fix zsh tab completion word-splitting language names containing spaces (e.g. `HTML (Jinja2)`, `Apache Conf`), see #3693 (@YoshKoz)
|
- Fix zsh tab completion word-splitting language names containing spaces (e.g. `HTML (Jinja2)`, `Apache Conf`), see #3693 (@YoshKoz)
|
||||||
- Fix zsh tab completion offering invalid `-l` arguments (file globs, paths, hidden filenames) sourced from the second column of `--list-languages`. Closes #3735, see #3737 (@truffle-dev)
|
- Fix zsh tab completion offering invalid `-l` arguments (file globs, paths, hidden filenames) sourced from the second column of `--list-languages`. Closes #3735, see #3737 (@truffle-dev)
|
||||||
|
- Fix `usize` underflow in `--list-languages` when `--terminal-width` is smaller than the longest language name, see #3812 (@greymoth-jp)
|
||||||
|
|
||||||
## Other
|
## Other
|
||||||
- Use git version of cross. See #3533 (@OctopusET)
|
- Use git version of cross. See #3533 (@OctopusET)
|
||||||
|
|||||||
+8
-1
@@ -152,7 +152,14 @@ pub fn get_languages(config: &Config, cache_dir: &Path) -> Result<String> {
|
|||||||
let comma_separator = ", ";
|
let comma_separator = ", ";
|
||||||
let separator = " ";
|
let separator = " ";
|
||||||
// Line-wrapping for the possible file extension overflow.
|
// Line-wrapping for the possible file extension overflow.
|
||||||
let desired_width = config.term_width - longest - separator.len();
|
// Clamp instead of subtracting: a tiny `--terminal-width` (smaller than the
|
||||||
|
// longest language name) would otherwise underflow `usize` and wrap to a huge
|
||||||
|
// value, silently disabling wrapping (and panicking in debug/overflow-checked
|
||||||
|
// builds). Mirrors the `saturating_sub` fix applied to `print_snip` in #3804.
|
||||||
|
let desired_width = config
|
||||||
|
.term_width
|
||||||
|
.saturating_sub(longest)
|
||||||
|
.saturating_sub(separator.len());
|
||||||
|
|
||||||
let style = if config.colored_output {
|
let style = if config.colored_output {
|
||||||
Green.normal()
|
Green.normal()
|
||||||
|
|||||||
Reference in New Issue
Block a user