diff --git a/Cargo.lock b/Cargo.lock index d15ecdf729..e57b9da8fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", ] diff --git a/crates/nu-command/Cargo.toml b/crates/nu-command/Cargo.toml index c37954e9c1..53e39353c0 100644 --- a/crates/nu-command/Cargo.toml +++ b/crates/nu-command/Cargo.toml @@ -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 } diff --git a/crates/nu-command/src/debug/inspect.rs b/crates/nu-command/src/debug/inspect.rs index 97217780bf..4a9f7bc4a5 100644 --- a/crates/nu-command/src/debug/inspect.rs +++ b/crates/nu-command/src/debug/inspect.rs @@ -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. diff --git a/crates/nu-command/src/platform/term_size.rs b/crates/nu-command/src/platform/term_size.rs index a4261dee81..b41d9da6c1 100644 --- a/crates/nu-command/src/platform/term_size.rs +++ b/crates/nu-command/src/platform/term_size.rs @@ -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 { 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, ) diff --git a/crates/nu-command/src/viewers/griddle.rs b/crates/nu-command/src/viewers/griddle.rs index 2774903d0f..730c5ec0df 100644 --- a/crates/nu-command/src/viewers/griddle.rs +++ b/crates/nu-command/src/viewers/griddle.rs @@ -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 diff --git a/crates/nu-command/src/viewers/table.rs b/crates/nu-command/src/viewers/table.rs index 50db949ced..43c9ed0b8d 100644 --- a/crates/nu-command/src/viewers/table.rs +++ b/crates/nu-command/src/viewers/table.rs @@ -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) -> 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 diff --git a/crates/nu-explore/Cargo.toml b/crates/nu-explore/Cargo.toml index 6ea09e3f13..e201262750 100644 --- a/crates/nu-explore/Cargo.toml +++ b/crates/nu-explore/Cargo.toml @@ -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 } diff --git a/crates/nu-explore/src/lib.rs b/crates/nu-explore/src/lib.rs index d645572c89..a6d4161631 100644 --- a/crates/nu-explore/src/lib.rs +++ b/crates/nu-explore/src/lib.rs @@ -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); } }