mirror of
https://github.com/nushell/nushell.git
synced 2025-08-18 14:52:12 +02:00
Add an option to move header on borders (#9796)
A patch to play with. Need to make a few tests after all. The question is what shall be done with `table.mode = none`, as it has no borders. ```nu $env.config.table.move_header = true ```  cc: @fdncred --------- Signed-off-by: Maxim Zhiburt <zhiburt@gmail.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