mirror of
https://github.com/nushell/nushell.git
synced 2024-11-26 02:13:47 +01:00
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:
parent
530ff3893e
commit
5959d1366a
@ -12,35 +12,28 @@ impl Command for TermSize {
|
||||
}
|
||||
|
||||
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 {
|
||||
Signature::build("term size")
|
||||
.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)
|
||||
Signature::build("term size").category(Category::Platform)
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![
|
||||
Example {
|
||||
description: "Return the width height of the terminal",
|
||||
description: "Return the columns (width) and rows (height) of the terminal",
|
||||
example: "term size",
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description: "Return the width (columns) of the terminal",
|
||||
example: "term size -c",
|
||||
description: "Return the columns (width) of the terminal",
|
||||
example: "(term size).columns",
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description: "Return the height (rows) of the terminal",
|
||||
example: "term size -r",
|
||||
description: "Return the rows (height) of the terminal",
|
||||
example: "(term size).rows",
|
||||
result: None,
|
||||
},
|
||||
]
|
||||
@ -54,24 +47,13 @@ impl Command for TermSize {
|
||||
_input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
let head = call.head;
|
||||
let wide = call.has_flag("columns");
|
||||
let tall = call.has_flag("rows");
|
||||
|
||||
let (cols, rows) = match terminal_size() {
|
||||
Some((w, h)) => (Width(w.0), Height(h.0)),
|
||||
None => (Width(0), Height(0)),
|
||||
};
|
||||
|
||||
Ok((match (wide, tall) {
|
||||
(true, false) => Value::Record {
|
||||
cols: vec!["columns".into()],
|
||||
vals: vec![Value::Int {
|
||||
val: cols.0 as i64,
|
||||
span: Span::test_data(),
|
||||
}],
|
||||
span: head,
|
||||
},
|
||||
(true, true) => Value::Record {
|
||||
Ok(Value::Record {
|
||||
cols: vec!["columns".into(), "rows".into()],
|
||||
vals: vec![
|
||||
Value::Int {
|
||||
@ -84,30 +66,7 @@ impl Command for TermSize {
|
||||
},
|
||||
],
|
||||
span: head,
|
||||
},
|
||||
(false, true) => Value::Record {
|
||||
cols: vec!["rows".into()],
|
||||
vals: vec![Value::Int {
|
||||
val: rows.0 as i64,
|
||||
span: Span::test_data(),
|
||||
}],
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user