Revert to term_size

Git invokes difftastic and then pipes stdout to less, but stderr still
goes to the terminal. term_size queries both stdout and stderr, so it
can still find the terminal width in this situation.

Previously, we'd always use a width of 80 when invoked by git.

terminal_size discussion:
https://github.com/eminence/terminal-size/issues/23

term_size does claim to support Windows, and #71 was not fixed by
changing libraries, so this seems reasonable.
pull/78/head
Wilfred Hughes 2021-12-19 12:48:52 +07:00
parent 382d498559
commit cb900c3463
3 changed files with 14 additions and 13 deletions

20
Cargo.lock generated

@ -171,7 +171,7 @@ dependencies = [
"regex",
"rustc-hash",
"strsim 0.10.0",
"terminal_size",
"term_size",
"tree-sitter",
"typed-arena",
"walkdir",
@ -435,22 +435,22 @@ dependencies = [
]
[[package]]
name = "termcolor"
version = "1.1.2"
name = "term_size"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
checksum = "1e4129646ca0ed8f45d09b929036bafad5377103edd06e50bf574b353d2b08d9"
dependencies = [
"winapi-util",
"libc",
"winapi",
]
[[package]]
name = "terminal_size"
version = "0.1.17"
name = "termcolor"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
dependencies = [
"libc",
"winapi",
"winapi-util",
]
[[package]]

@ -38,7 +38,7 @@ pretty_env_logger = "0.4.0"
mimalloc = { version = "0.1.26", default-features = false }
radix-heap = "0.4.1"
walkdir = "2.3.2"
terminal_size = "0.1.17"
term_size = "0.3.2"
[dev-dependencies]
pretty_assertions = "1.0.0"
@ -58,3 +58,5 @@ debug = false
[[bin]]
name = "difft"
path = "src/main.rs"
[features]

@ -6,7 +6,6 @@ use std::{
collections::{HashMap, HashSet},
env,
};
use terminal_size::terminal_size;
use crate::{
context::opposite_positions,
@ -29,7 +28,7 @@ fn display_width() -> usize {
}
}
terminal_size().map(|(w, _)| w.0 as usize).unwrap_or(80)
term_size::dimensions().map(|(w, _)| w).unwrap_or(80)
}
/// Split `s` by newlines, but guarantees that the output is nonempty.