Remove unnecessary flags from term size (#6651)

The columns and rows can be obtained individually using

(term size).columns
(term size).rows
This commit is contained in:
Dan Davison 2022-10-01 08:00:54 -04:00 committed by GitHub
parent 530ff3893e
commit 5959d1366a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,35 +12,28 @@ impl Command for TermSize {
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
"Returns the terminal size" "Returns a record containing the number of columns (width) and rows (height) of the terminal"
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("term size") Signature::build("term size").category(Category::Platform)
.switch(
"columns",
"Report only the width of the terminal",
Some('c'),
)
.switch("rows", "Report only the height of the terminal", Some('r'))
.category(Category::Platform)
} }
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![ vec![
Example { Example {
description: "Return the width height of the terminal", description: "Return the columns (width) and rows (height) of the terminal",
example: "term size", example: "term size",
result: None, result: None,
}, },
Example { Example {
description: "Return the width (columns) of the terminal", description: "Return the columns (width) of the terminal",
example: "term size -c", example: "(term size).columns",
result: None, result: None,
}, },
Example { Example {
description: "Return the height (rows) of the terminal", description: "Return the rows (height) of the terminal",
example: "term size -r", example: "(term size).rows",
result: None, result: None,
}, },
] ]
@ -54,60 +47,26 @@ impl Command for TermSize {
_input: PipelineData, _input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> { ) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
let head = call.head; let head = call.head;
let wide = call.has_flag("columns");
let tall = call.has_flag("rows");
let (cols, rows) = match terminal_size() { let (cols, rows) = match terminal_size() {
Some((w, h)) => (Width(w.0), Height(h.0)), Some((w, h)) => (Width(w.0), Height(h.0)),
None => (Width(0), Height(0)), None => (Width(0), Height(0)),
}; };
Ok((match (wide, tall) { Ok(Value::Record {
(true, false) => Value::Record { cols: vec!["columns".into(), "rows".into()],
cols: vec!["columns".into()], vals: vec![
vals: vec![Value::Int { Value::Int {
val: cols.0 as i64, val: cols.0 as i64,
span: Span::test_data(), span: Span::test_data(),
}], },
span: head, Value::Int {
},
(true, true) => Value::Record {
cols: vec!["columns".into(), "rows".into()],
vals: vec![
Value::Int {
val: cols.0 as i64,
span: Span::test_data(),
},
Value::Int {
val: rows.0 as i64,
span: Span::test_data(),
},
],
span: head,
},
(false, true) => Value::Record {
cols: vec!["rows".into()],
vals: vec![Value::Int {
val: rows.0 as i64, val: rows.0 as i64,
span: Span::test_data(), span: Span::test_data(),
}], },
span: head, ],
}, span: head,
(false, false) => Value::Record { }
cols: vec!["columns".into(), "rows".into()],
vals: vec![
Value::Int {
val: cols.0 as i64,
span: Span::test_data(),
},
Value::Int {
val: rows.0 as i64,
span: Span::test_data(),
},
],
span: head,
},
})
.into_pipeline_data()) .into_pipeline_data())
} }
} }