diff --git a/crates/nu-cli/src/commands/autoview.rs b/crates/nu-cli/src/commands/autoview.rs index ccf3e35f7..61b1ad1d5 100644 --- a/crates/nu-cli/src/commands/autoview.rs +++ b/crates/nu-cli/src/commands/autoview.rs @@ -80,13 +80,24 @@ pub fn autoview(context: RunnableContext) -> Result { 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 { 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::>().iter() .fold(0, |acc, len| acc + len.len()) diff --git a/docs/commands/config.md b/docs/commands/config.md index 94ff2772e..0391f96fb 100644 --- a/docs/commands/config.md +++ b/docs/commands/config.md @@ -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