forked from extern/nushell
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:
@ -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.
|
||||
|
@ -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,
|
||||
)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user