mirror of
https://github.com/nushell/nushell.git
synced 2024-11-30 20:34:16 +01:00
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:
parent
83d8e936ad
commit
dd3a3a2717
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -3358,7 +3358,6 @@ dependencies = [
|
|||||||
"sysinfo 0.32.0",
|
"sysinfo 0.32.0",
|
||||||
"tabled",
|
"tabled",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"terminal_size 0.4.0",
|
|
||||||
"titlecase",
|
"titlecase",
|
||||||
"toml 0.8.19",
|
"toml 0.8.19",
|
||||||
"trash",
|
"trash",
|
||||||
@ -3427,7 +3426,6 @@ dependencies = [
|
|||||||
"nu-utils",
|
"nu-utils",
|
||||||
"ratatui",
|
"ratatui",
|
||||||
"strip-ansi-escapes",
|
"strip-ansi-escapes",
|
||||||
"terminal_size 0.4.0",
|
|
||||||
"unicode-width 0.1.11",
|
"unicode-width 0.1.11",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -86,7 +86,6 @@ serde_yaml = { workspace = true }
|
|||||||
sha2 = { workspace = true }
|
sha2 = { workspace = true }
|
||||||
sysinfo = { workspace = true }
|
sysinfo = { workspace = true }
|
||||||
tabled = { workspace = true, features = ["ansi"], default-features = false }
|
tabled = { workspace = true, features = ["ansi"], default-features = false }
|
||||||
terminal_size = { workspace = true }
|
|
||||||
titlecase = { workspace = true }
|
titlecase = { workspace = true }
|
||||||
toml = { workspace = true, features = ["preserve_order"] }
|
toml = { workspace = true, features = ["preserve_order"] }
|
||||||
unicode-segmentation = { workspace = true }
|
unicode-segmentation = { workspace = true }
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use super::inspect_table;
|
use super::inspect_table;
|
||||||
|
use crossterm::terminal::size;
|
||||||
use nu_engine::command_prelude::*;
|
use nu_engine::command_prelude::*;
|
||||||
use terminal_size::{terminal_size, Height, Width};
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Inspect;
|
pub struct Inspect;
|
||||||
@ -38,12 +38,9 @@ impl Command for Inspect {
|
|||||||
let original_input = input_val.clone();
|
let original_input = input_val.clone();
|
||||||
let description = input_val.get_type().to_string();
|
let description = input_val.get_type().to_string();
|
||||||
|
|
||||||
let (cols, _rows) = match terminal_size() {
|
let (cols, _rows) = size().unwrap_or((0, 0));
|
||||||
Some((w, h)) => (Width(w.0), Height(h.0)),
|
|
||||||
None => (Width(0), Height(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
|
// 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.
|
// tabular output. If we printed to stdout, nushell would get confused with two outputs.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
use crossterm::terminal::size;
|
||||||
use nu_engine::command_prelude::*;
|
use nu_engine::command_prelude::*;
|
||||||
use terminal_size::{terminal_size, Height, Width};
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct TermSize;
|
pub struct TermSize;
|
||||||
@ -51,15 +51,12 @@ impl Command for TermSize {
|
|||||||
) -> Result<PipelineData, ShellError> {
|
) -> Result<PipelineData, ShellError> {
|
||||||
let head = call.head;
|
let head = call.head;
|
||||||
|
|
||||||
let (cols, rows) = match terminal_size() {
|
let (cols, rows) = size().unwrap_or((0, 0));
|
||||||
Some((w, h)) => (Width(w.0), Height(h.0)),
|
|
||||||
None => (Width(0), Height(0)),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(Value::record(
|
Ok(Value::record(
|
||||||
record! {
|
record! {
|
||||||
"columns" => Value::int(cols.0 as i64, head),
|
"columns" => Value::int(cols as i64, head),
|
||||||
"rows" => Value::int(rows.0 as i64, head),
|
"rows" => Value::int(rows as i64, head),
|
||||||
},
|
},
|
||||||
head,
|
head,
|
||||||
)
|
)
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
// use super::icons::{icon_for_file, iconify_style_ansi_to_nu};
|
// use super::icons::{icon_for_file, iconify_style_ansi_to_nu};
|
||||||
use super::icons::icon_for_file;
|
use super::icons::icon_for_file;
|
||||||
|
use crossterm::terminal::size;
|
||||||
use lscolors::Style;
|
use lscolors::Style;
|
||||||
use nu_engine::{command_prelude::*, env_to_string};
|
use nu_engine::{command_prelude::*, env_to_string};
|
||||||
use nu_protocol::Config;
|
use nu_protocol::Config;
|
||||||
use nu_term_grid::grid::{Alignment, Cell, Direction, Filling, Grid, GridOptions};
|
use nu_term_grid::grid::{Alignment, Cell, Direction, Filling, Grid, GridOptions};
|
||||||
use nu_utils::get_ls_colors;
|
use nu_utils::get_ls_colors;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use terminal_size::{Height, Width};
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Griddle;
|
pub struct Griddle;
|
||||||
@ -192,7 +192,7 @@ fn create_grid_output(
|
|||||||
|
|
||||||
let cols = if let Some(col) = width_param {
|
let cols = if let Some(col) = width_param {
|
||||||
col as u16
|
col as u16
|
||||||
} else if let Some((Width(w), Height(_h))) = terminal_size::terminal_size() {
|
} else if let Ok((w, _h)) = size() {
|
||||||
w
|
w
|
||||||
} else {
|
} else {
|
||||||
80u16
|
80u16
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// overall reduce the redundant calls to StyleComputer etc.
|
// overall reduce the redundant calls to StyleComputer etc.
|
||||||
// the goal is to configure it once...
|
// the goal is to configure it once...
|
||||||
|
|
||||||
|
use crossterm::terminal::size;
|
||||||
use lscolors::{LsColors, Style};
|
use lscolors::{LsColors, Style};
|
||||||
use nu_color_config::{color_from_hex, StyleComputer, TextStyle};
|
use nu_color_config::{color_from_hex, StyleComputer, TextStyle};
|
||||||
use nu_engine::{command_prelude::*, env_to_string};
|
use nu_engine::{command_prelude::*, env_to_string};
|
||||||
@ -22,7 +23,6 @@ use std::{
|
|||||||
str::FromStr,
|
str::FromStr,
|
||||||
time::Instant,
|
time::Instant,
|
||||||
};
|
};
|
||||||
use terminal_size::{Height, Width};
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
const STREAM_PAGE_SIZE: usize = 1000;
|
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 {
|
fn get_width_param(width_param: Option<i64>) -> usize {
|
||||||
if let Some(col) = width_param {
|
if let Some(col) = width_param {
|
||||||
col as usize
|
col as usize
|
||||||
} else if let Some((Width(w), Height(_))) = terminal_size::terminal_size() {
|
} else if let Ok((w, _h)) = size() {
|
||||||
w as usize
|
w as usize
|
||||||
} else {
|
} else {
|
||||||
80
|
80
|
||||||
|
@ -27,7 +27,6 @@ nu-pretty-hex = { path = "../nu-pretty-hex", version = "0.100.1" }
|
|||||||
|
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
log = { workspace = true }
|
log = { workspace = true }
|
||||||
terminal_size = { workspace = true }
|
|
||||||
strip-ansi-escapes = { workspace = true }
|
strip-ansi-escapes = { workspace = true }
|
||||||
crossterm = { workspace = true }
|
crossterm = { workspace = true }
|
||||||
ratatui = { workspace = true }
|
ratatui = { workspace = true }
|
||||||
|
@ -9,6 +9,7 @@ mod views;
|
|||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use commands::{ExpandCmd, HelpCmd, NuCmd, QuitCmd, TableCmd, TryCmd};
|
use commands::{ExpandCmd, HelpCmd, NuCmd, QuitCmd, TableCmd, TryCmd};
|
||||||
|
use crossterm::terminal::size;
|
||||||
pub use default_context::add_explore_context;
|
pub use default_context::add_explore_context;
|
||||||
pub use explore::Explore;
|
pub use explore::Explore;
|
||||||
use explore::ExploreConfig;
|
use explore::ExploreConfig;
|
||||||
@ -19,7 +20,6 @@ use nu_protocol::{
|
|||||||
};
|
};
|
||||||
use pager::{Page, Pager, PagerConfig};
|
use pager::{Page, Pager, PagerConfig};
|
||||||
use registry::CommandRegistry;
|
use registry::CommandRegistry;
|
||||||
use terminal_size::{Height, Width};
|
|
||||||
use views::{BinaryView, Orientation, Preview, RecordView};
|
use views::{BinaryView, Orientation, Preview, RecordView};
|
||||||
|
|
||||||
mod util {
|
mod util {
|
||||||
@ -80,7 +80,7 @@ fn create_record_view(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if config.tail {
|
if config.tail {
|
||||||
if let Some((Width(w), Height(h))) = terminal_size::terminal_size() {
|
if let Ok((w, h)) = size() {
|
||||||
view.tail(w, h);
|
view.tail(w, h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user