refactor: replace term_size with terminal_size (#3087)

This commit is contained in:
David Knaack
2021-09-23 17:52:51 +02:00
committed by GitHub
parent 888a653c32
commit b22c54fccc
4 changed files with 11 additions and 9 deletions
+3 -2
View File
@@ -15,6 +15,7 @@ use std::fs;
use std::path::{Path, PathBuf};
use std::string::String;
use std::time::{Duration, Instant};
use terminal_size::terminal_size;
/// 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
@@ -138,8 +139,8 @@ impl<'a> Context<'a> {
repo: OnceCell::new(),
shell,
right,
width: term_size::dimensions()
.map(|(width, _)| width)
width: terminal_size()
.map(|(w, _)| w.0 as usize)
.unwrap_or_default(),
#[cfg(test)]
env: HashMap::new(),
+3 -2
View File
@@ -5,6 +5,7 @@ use std::collections::BTreeSet;
use std::fmt::{self, Debug, Write as FmtWrite};
use std::io::{self, Write};
use std::time::Duration;
use terminal_size::terminal_size;
use unicode_segmentation::UnicodeSegmentation;
use unicode_width::UnicodeWidthChar;
@@ -224,8 +225,8 @@ pub fn explain(args: ArgMatches) {
// Overall a line looks like this: " "{module value}" ({xxxms}) - {description}".
const PADDING_WIDTH: usize = 11;
let desc_width = term_size::dimensions()
.map(|(w, _)| w)
let desc_width = terminal_size()
.map(|(w, _)| w.0 as usize)
// 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));