1
0
mirror of https://github.com/sharkdp/bat synced 2026-06-28 13:13:19 +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:
Keith Hall
2026-06-27 06:12:21 +03:00
committed by GitHub
2 changed files with 9 additions and 1 deletions
+1
View File
@@ -46,6 +46,7 @@
- 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 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
- Use git version of cross. See #3533 (@OctopusET)
+8 -1
View File
@@ -152,7 +152,14 @@ pub fn get_languages(config: &Config, cache_dir: &Path) -> Result<String> {
let comma_separator = ", ";
let separator = " ";
// 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 {
Green.normal()