forked from extern/nushell
Tweak auto-rotate for single row output (#1861)
* added helper to convert data to strings added ability to auto-rotate single row output if row will be greater than terminal width * Added pivot_to_fit config value * Added ColumnPath to convert_to_string helper * Figured out I had to run `cargo fmt --all -- --check` Co-authored-by: Darren Schroeder <fdncred@hotmail.com>
This commit is contained in:
@ -84,6 +84,10 @@ pub fn autoview(context: RunnableContext) -> Result<OutputStream, ShellError> {
|
||||
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,
|
||||
};
|
||||
|
||||
Ok(OutputStream::new(async_stream! {
|
||||
let (mut input_stream, context) = RunnableContextWithoutInput::convert(context);
|
||||
@ -221,7 +225,14 @@ pub fn autoview(context: RunnableContext) -> Result<OutputStream, ShellError> {
|
||||
yield Err(e);
|
||||
}
|
||||
|
||||
Value { value: UntaggedValue::Row(row), ..} if !no_auto_pivot => {
|
||||
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
|
||||
(row.entries.iter().map(|(k,v)| v.convert_to_string())
|
||||
.collect::<Vec<_>>().iter()
|
||||
.fold(0, |acc, len| acc + len.len())
|
||||
+
|
||||
(row.entries.iter().map(|(k,_)| k.chars()).count() * 2))
|
||||
> textwrap::termwidth()) => {
|
||||
use prettytable::format::{FormatBuilder, LinePosition, LineSeparator};
|
||||
use prettytable::{color, Attr, Cell, Row, Table};
|
||||
use crate::data::value::{format_leaf, style_leaf};
|
||||
|
Reference in New Issue
Block a user