mirror of
https://github.com/nushell/nushell.git
synced 2025-08-18 17:58:24 +02:00
Add an option to set header on border (style) (#9920)
fix #9796 Sorry that you've had the issues. I've actually encountered them yesterday too (seems like they have appeared after some refactoring in the middle) but was not able to fix that rapid. Created a bunch of tests. cc: @fdncred Note: This option will be certainly slower then a default ones. (could be fixed but ... maybe later). Maybe it shall be cited somewhere. PS: Haven't tested on a wrapped/expanded tables. --------- Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com> Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
use nu_color_config::StyleComputer;
|
||||
use nu_protocol::{Span, Value};
|
||||
use nu_table::{value_to_clean_styled_string, value_to_styled_string, BuildConfig, ExpandedTable};
|
||||
use nu_table::{
|
||||
common::{nu_value_to_string, nu_value_to_string_clean},
|
||||
ExpandedTable, TableOpts,
|
||||
};
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -18,9 +21,9 @@ pub fn try_build_table(
|
||||
try_build_map(cols, vals, span, style_computer, ctrlc, config)
|
||||
}
|
||||
val if matches!(val, Value::String { .. }) => {
|
||||
value_to_clean_styled_string(&val, config, style_computer).0
|
||||
nu_value_to_string_clean(&val, config, style_computer).0
|
||||
}
|
||||
val => value_to_styled_string(&val, config, style_computer).0,
|
||||
val => nu_value_to_string(&val, config, style_computer).0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,12 +35,19 @@ fn try_build_map(
|
||||
ctrlc: Option<Arc<AtomicBool>>,
|
||||
config: &NuConfig,
|
||||
) -> String {
|
||||
let opts = BuildConfig::new(ctrlc, config, style_computer, Span::unknown(), usize::MAX);
|
||||
let opts = TableOpts::new(
|
||||
config,
|
||||
style_computer,
|
||||
ctrlc,
|
||||
Span::unknown(),
|
||||
0,
|
||||
usize::MAX,
|
||||
);
|
||||
let result = ExpandedTable::new(None, false, String::new()).build_map(&cols, &vals, opts);
|
||||
match result {
|
||||
Ok(Some(result)) => result,
|
||||
Ok(None) | Err(_) => {
|
||||
value_to_styled_string(&Value::Record { cols, vals, span }, config, style_computer).0
|
||||
nu_value_to_string(&Value::Record { cols, vals, span }, config, style_computer).0
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,13 +59,20 @@ fn try_build_list(
|
||||
span: Span,
|
||||
style_computer: &StyleComputer,
|
||||
) -> String {
|
||||
let opts = BuildConfig::new(ctrlc, config, style_computer, Span::unknown(), usize::MAX);
|
||||
let result = ExpandedTable::new(None, false, String::new()).build_list(&vals, opts, 0);
|
||||
let opts = TableOpts::new(
|
||||
config,
|
||||
style_computer,
|
||||
ctrlc,
|
||||
Span::unknown(),
|
||||
0,
|
||||
usize::MAX,
|
||||
);
|
||||
let result = ExpandedTable::new(None, false, String::new()).build_list(&vals, opts);
|
||||
match result {
|
||||
Ok(Some(out)) => out,
|
||||
Ok(None) | Err(_) => {
|
||||
// it means that the list is empty
|
||||
value_to_styled_string(&Value::List { vals, span }, config, style_computer).0
|
||||
nu_value_to_string(&Value::List { vals, span }, config, style_computer).0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user