Prefer terminal_width crate so we support more platforms

term_width is unmaintained and does not support Windows.

Fixes #71
pull/77/head
Wilfred Hughes 2021-12-07 23:24:13 +07:00
parent bffbf1b779
commit 6f1baae23e
4 changed files with 24 additions and 14 deletions

@ -1,5 +1,9 @@
## 0.14 (unreleased)
### Display
Fixed terminal width calculations on Windows.
### Build
Fixed some build issues on Windows.

20
Cargo.lock generated

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

@ -26,7 +26,6 @@ colored = "2.0.0"
diff = "0.1.12"
clap = "2.33.3"
itertools = "0.10.1"
term_size = "0.3.2"
typed-arena = "2.0.1"
rustc-hash = "1.1.0"
strsim = "0.10.0"
@ -39,6 +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"
[dev-dependencies]
pretty_assertions = "1.0.0"

@ -5,6 +5,7 @@ use std::{
cmp::max,
collections::{HashMap, HashSet},
};
use terminal_size::terminal_size;
use crate::{
context::opposite_positions,
@ -17,8 +18,8 @@ use crate::{
const SPACER: &str = " ";
fn term_width() -> Option<usize> {
term_size::dimensions().map(|(w, _)| w)
fn term_width() -> Option<u16> {
terminal_size().map(|(w, _)| w.0)
}
/// Split `s` by newlines, but guarantees that the output is nonempty.
@ -238,7 +239,12 @@ pub fn display_hunks(
let no_rhs_changes = hunk.lines.iter().all(|(_, r)| r.is_none());
let same_lines = aligned_lines.iter().all(|(l, r)| l == r);
let widths = Widths::new(term_width().unwrap_or(80), &aligned_lines, lhs_src, rhs_src);
let widths = Widths::new(
term_width().unwrap_or(80) as usize,
&aligned_lines,
lhs_src,
rhs_src,
);
for (lhs_line_num, rhs_line_num) in aligned_lines {
let (display_lhs_line_num, display_rhs_line_num) = display_line_nums(
lhs_line_num,