remove terminal_size crate everywhere it makes sense (#14423)

# Description

This PR removes the `terminal_size` crate everywhere that it made sense.
I replaced it with crossterm's version called `size`. The places I
didn't remove it were the places that did not have a dependency on
crossterm. So, I thought it was "cheaper" to have a dep on term_size vs
crossterm in those locations.
This commit is contained in:
Darren Schroeder 2024-11-23 21:37:12 -06:00 committed by GitHub
parent 83d8e936ad
commit dd3a3a2717
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 13 additions and 23 deletions

2
Cargo.lock generated
View file

@ -3358,7 +3358,6 @@ dependencies = [
"sysinfo 0.32.0",
"tabled",
"tempfile",
"terminal_size 0.4.0",
"titlecase",
"toml 0.8.19",
"trash",
@ -3427,7 +3426,6 @@ dependencies = [
"nu-utils",
"ratatui",
"strip-ansi-escapes",
"terminal_size 0.4.0",
"unicode-width 0.1.11",
]

View file

@ -86,7 +86,6 @@ serde_yaml = { workspace = true }
sha2 = { workspace = true }
sysinfo = { workspace = true }
tabled = { workspace = true, features = ["ansi"], default-features = false }
terminal_size = { workspace = true }
titlecase = { workspace = true }
toml = { workspace = true, features = ["preserve_order"] }
unicode-segmentation = { workspace = true }

View file

@ -1,6 +1,6 @@
use super::inspect_table;
use crossterm::terminal::size;
use nu_engine::command_prelude::*;
use terminal_size::{terminal_size, Height, Width};
#[derive(Clone)]
pub struct Inspect;
@ -38,12 +38,9 @@ impl Command for Inspect {
let original_input = input_val.clone();
let description = input_val.get_type().to_string();
let (cols, _rows) = match terminal_size() {
Some((w, h)) => (Width(w.0), Height(h.0)),
None => (Width(0), Height(0)),
};
let (cols, _rows) = size().unwrap_or((0, 0));
let table = inspect_table::build_table(input_val, description, cols.0 as usize);
let table = inspect_table::build_table(input_val, description, cols as usize);
// Note that this is printed to stderr. The reason for this is so it doesn't disrupt the regular nushell
// tabular output. If we printed to stdout, nushell would get confused with two outputs.

View file

@ -1,5 +1,5 @@
use crossterm::terminal::size;
use nu_engine::command_prelude::*;
use terminal_size::{terminal_size, Height, Width};
#[derive(Clone)]
pub struct TermSize;
@ -51,15 +51,12 @@ impl Command for TermSize {
) -> Result<PipelineData, ShellError> {
let head = call.head;
let (cols, rows) = match terminal_size() {
Some((w, h)) => (Width(w.0), Height(h.0)),
None => (Width(0), Height(0)),
};
let (cols, rows) = size().unwrap_or((0, 0));
Ok(Value::record(
record! {
"columns" => Value::int(cols.0 as i64, head),
"rows" => Value::int(rows.0 as i64, head),
"columns" => Value::int(cols as i64, head),
"rows" => Value::int(rows as i64, head),
},
head,
)

View file

@ -1,12 +1,12 @@
// use super::icons::{icon_for_file, iconify_style_ansi_to_nu};
use super::icons::icon_for_file;
use crossterm::terminal::size;
use lscolors::Style;
use nu_engine::{command_prelude::*, env_to_string};
use nu_protocol::Config;
use nu_term_grid::grid::{Alignment, Cell, Direction, Filling, Grid, GridOptions};
use nu_utils::get_ls_colors;
use std::path::Path;
use terminal_size::{Height, Width};
#[derive(Clone)]
pub struct Griddle;
@ -192,7 +192,7 @@ fn create_grid_output(
let cols = if let Some(col) = width_param {
col as u16
} else if let Some((Width(w), Height(_h))) = terminal_size::terminal_size() {
} else if let Ok((w, _h)) = size() {
w
} else {
80u16

View file

@ -2,6 +2,7 @@
// overall reduce the redundant calls to StyleComputer etc.
// the goal is to configure it once...
use crossterm::terminal::size;
use lscolors::{LsColors, Style};
use nu_color_config::{color_from_hex, StyleComputer, TextStyle};
use nu_engine::{command_prelude::*, env_to_string};
@ -22,7 +23,6 @@ use std::{
str::FromStr,
time::Instant,
};
use terminal_size::{Height, Width};
use url::Url;
const STREAM_PAGE_SIZE: usize = 1000;
@ -30,7 +30,7 @@ const STREAM_PAGE_SIZE: usize = 1000;
fn get_width_param(width_param: Option<i64>) -> usize {
if let Some(col) = width_param {
col as usize
} else if let Some((Width(w), Height(_))) = terminal_size::terminal_size() {
} else if let Ok((w, _h)) = size() {
w as usize
} else {
80

View file

@ -27,7 +27,6 @@ nu-pretty-hex = { path = "../nu-pretty-hex", version = "0.100.1" }
anyhow = { workspace = true }
log = { workspace = true }
terminal_size = { workspace = true }
strip-ansi-escapes = { workspace = true }
crossterm = { workspace = true }
ratatui = { workspace = true }

View file

@ -9,6 +9,7 @@ mod views;
use anyhow::Result;
use commands::{ExpandCmd, HelpCmd, NuCmd, QuitCmd, TableCmd, TryCmd};
use crossterm::terminal::size;
pub use default_context::add_explore_context;
pub use explore::Explore;
use explore::ExploreConfig;
@ -19,7 +20,6 @@ use nu_protocol::{
};
use pager::{Page, Pager, PagerConfig};
use registry::CommandRegistry;
use terminal_size::{Height, Width};
use views::{BinaryView, Orientation, Preview, RecordView};
mod util {
@ -80,7 +80,7 @@ fn create_record_view(
}
if config.tail {
if let Some((Width(w), Height(h))) = terminal_size::terminal_size() {
if let Ok((w, h)) = size() {
view.tail(w, h);
}
}