refactor: replace `term_size` with `terminal_size` (#3087)
This commit is contained in:
parent
888a653c32
commit
b22c54fccc
|
@ -1705,7 +1705,7 @@ dependencies = [
|
||||||
"strsim 0.10.0",
|
"strsim 0.10.0",
|
||||||
"sys-info",
|
"sys-info",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"term_size",
|
"terminal_size",
|
||||||
"toml",
|
"toml",
|
||||||
"unicode-segmentation",
|
"unicode-segmentation",
|
||||||
"unicode-width",
|
"unicode-width",
|
||||||
|
@ -1815,10 +1815,10 @@ dependencies = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "term_size"
|
name = "terminal_size"
|
||||||
version = "0.3.2"
|
version = "0.1.17"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1e4129646ca0ed8f45d09b929036bafad5377103edd06e50bf574b353d2b08d9"
|
checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"winapi",
|
"winapi",
|
||||||
|
|
|
@ -58,7 +58,7 @@ os_info = "3.0.7"
|
||||||
urlencoding = "2.1.0"
|
urlencoding = "2.1.0"
|
||||||
open = "2.0.1"
|
open = "2.0.1"
|
||||||
unicode-width = "0.1.9"
|
unicode-width = "0.1.9"
|
||||||
term_size = "0.3.2"
|
terminal_size = "0.1.17"
|
||||||
quick-xml = "0.22.0"
|
quick-xml = "0.22.0"
|
||||||
rand = "0.8.4"
|
rand = "0.8.4"
|
||||||
serde = { version = "1.0.130", features = ["derive"] }
|
serde = { version = "1.0.130", features = ["derive"] }
|
||||||
|
|
|
@ -15,6 +15,7 @@ use std::fs;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::string::String;
|
use std::string::String;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
use terminal_size::terminal_size;
|
||||||
|
|
||||||
/// Context contains data or common methods that may be used by multiple modules.
|
/// Context contains data or common methods that may be used by multiple modules.
|
||||||
/// The data contained within Context will be relevant to this particular rendering
|
/// The data contained within Context will be relevant to this particular rendering
|
||||||
|
@ -138,8 +139,8 @@ impl<'a> Context<'a> {
|
||||||
repo: OnceCell::new(),
|
repo: OnceCell::new(),
|
||||||
shell,
|
shell,
|
||||||
right,
|
right,
|
||||||
width: term_size::dimensions()
|
width: terminal_size()
|
||||||
.map(|(width, _)| width)
|
.map(|(w, _)| w.0 as usize)
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
env: HashMap::new(),
|
env: HashMap::new(),
|
||||||
|
|
|
@ -5,6 +5,7 @@ use std::collections::BTreeSet;
|
||||||
use std::fmt::{self, Debug, Write as FmtWrite};
|
use std::fmt::{self, Debug, Write as FmtWrite};
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
use terminal_size::terminal_size;
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
use unicode_width::UnicodeWidthChar;
|
use unicode_width::UnicodeWidthChar;
|
||||||
|
|
||||||
|
@ -224,8 +225,8 @@ pub fn explain(args: ArgMatches) {
|
||||||
// Overall a line looks like this: " "{module value}" ({xxxms}) - {description}".
|
// Overall a line looks like this: " "{module value}" ({xxxms}) - {description}".
|
||||||
const PADDING_WIDTH: usize = 11;
|
const PADDING_WIDTH: usize = 11;
|
||||||
|
|
||||||
let desc_width = term_size::dimensions()
|
let desc_width = terminal_size()
|
||||||
.map(|(w, _)| w)
|
.map(|(w, _)| w.0 as usize)
|
||||||
// Add padding length to module length to avoid text overflow. This line also assures desc_width >= 0.
|
// Add padding length to module length to avoid text overflow. This line also assures desc_width >= 0.
|
||||||
.map(|width| width - std::cmp::min(width, max_module_width + PADDING_WIDTH));
|
.map(|width| width - std::cmp::min(width, max_module_width + PADDING_WIDTH));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue