mirror of
https://github.com/nushell/nushell.git
synced 2025-01-11 08:48:23 +01:00
Merge pivot options (#1888)
This commit is contained in:
parent
cb6ccc3c5a
commit
f0fc9e1038
@ -80,13 +80,24 @@ pub fn autoview(context: RunnableContext) -> Result<OutputStream, ShellError> {
|
||||
let binary = context.get_command("binaryview");
|
||||
let text = context.get_command("textview");
|
||||
let table = context.get_command("table");
|
||||
let no_auto_pivot = match config::config(Tag::unknown())?.get("no_auto_pivot") {
|
||||
Some(val) => val.is_true(),
|
||||
_ => false,
|
||||
};
|
||||
let pivot_to_fit = match config::config(Tag::unknown())?.get("pivot_to_fit") {
|
||||
Some(val) => val.is_true(),
|
||||
_ => false,
|
||||
|
||||
#[derive(PartialEq)]
|
||||
enum AutoPivotMode {
|
||||
Auto,
|
||||
Always,
|
||||
Never,
|
||||
}
|
||||
|
||||
let pivot_mode = crate::data::config::config(Tag::unknown());
|
||||
let pivot_mode = if let Some(v) = pivot_mode?.get("pivot_mode") {
|
||||
match v.as_string() {
|
||||
Ok(m) if m.to_lowercase() == "auto" => AutoPivotMode::Auto,
|
||||
Ok(m) if m.to_lowercase() == "always" => AutoPivotMode::Always,
|
||||
Ok(m) if m.to_lowercase() == "never" => AutoPivotMode::Never,
|
||||
_ => AutoPivotMode::Always,
|
||||
}
|
||||
} else {
|
||||
AutoPivotMode::Always
|
||||
};
|
||||
|
||||
Ok(OutputStream::new(async_stream! {
|
||||
@ -234,8 +245,9 @@ pub fn autoview(context: RunnableContext) -> Result<OutputStream, ShellError> {
|
||||
yield Err(e);
|
||||
}
|
||||
|
||||
Value { value: UntaggedValue::Row(row), ..} if !no_auto_pivot
|
||||
|| (pivot_to_fit && // Or if the row character count + number of headers * 2 (for padding) > terminal width
|
||||
Value { value: UntaggedValue::Row(row), ..}
|
||||
if pivot_mode == AutoPivotMode::Always ||
|
||||
(pivot_mode == AutoPivotMode::Auto &&
|
||||
(row.entries.iter().map(|(k,v)| v.convert_to_string())
|
||||
.collect::<Vec<_>>().iter()
|
||||
.fold(0, |acc, len| acc + len.len())
|
||||
|
@ -39,7 +39,7 @@ Syntax: `config {flags}`
|
||||
| key_timeout | integer (milliseconds) | vi: the delay to wait for a longer key sequence after ESC |
|
||||
| history_size | integer | maximum entries that will be stored in history (100,000 default) |
|
||||
| completion_mode | "circular" or "list" | changes completion type to "circular" (default) or "list" mode |
|
||||
| no_auto_pivot | boolean | whether or not to automatically pivot single-row results |
|
||||
| pivot_mode | "auto" or "always" or "never" | "auto" will only pivot single row tables if the output is greater than the terminal width. "always" will always pivot single row tables. "never" will never pivot single row tables. |
|
||||
| complete_from_path | boolean | whether or not to complete names of binaries on PATH (default true) |
|
||||
|
||||
## Examples
|
||||
|
Loading…
Reference in New Issue
Block a user