feat(table): make missing value symbol configurable (#15647)

Co-authored-by: Bahex <17417311+Bahex@users.noreply.github.com>
This commit is contained in:
Bahex
2025-04-27 23:58:39 +03:00
committed by GitHub
parent 12ccaf5e33
commit d8bec8668f
6 changed files with 54 additions and 6 deletions

View File

@ -71,10 +71,9 @@ pub fn nu_value_to_string_clean(val: &Value, cfg: &Config, style_comp: &StyleCom
(text, style)
}
pub fn error_sign(style_computer: &StyleComputer) -> (String, TextStyle) {
pub fn error_sign(text: String, style_computer: &StyleComputer) -> (String, TextStyle) {
// Though holes are not the same as null, the closure for "empty" is passed a null anyway.
let text = String::from("");
let style = style_computer.compute("empty", &Value::nothing(Span::unknown()));
(text, TextStyle::with_style(Alignment::Center, style))
}
@ -122,9 +121,9 @@ pub fn get_value_style(value: &Value, config: &Config, style_computer: &StyleCom
}
}
pub fn get_empty_style(style_computer: &StyleComputer) -> NuText {
pub fn get_empty_style(text: String, style_computer: &StyleComputer) -> NuText {
(
String::from(""),
text,
TextStyle::with_style(
Alignment::Right,
style_computer.compute("empty", &Value::nothing(Span::unknown())),

View File

@ -507,7 +507,10 @@ fn expand_entry_with_header(item: &Value, header: &str, cfg: Cfg<'_>) -> CellOut
match item {
Value::Record { val, .. } => match val.get(header) {
Some(val) => expand_entry(val, cfg),
None => CellOutput::styled(error_sign(&cfg.opts.style_computer)),
None => CellOutput::styled(error_sign(
cfg.opts.config.table.missing_value_symbol.clone(),
&cfg.opts.style_computer,
)),
},
_ => expand_entry(item, cfg),
}

View File

@ -206,7 +206,10 @@ fn get_string_value_with_header(item: &Value, header: &str, opts: &TableOpts) ->
match item {
Value::Record { val, .. } => match val.get(header) {
Some(value) => get_string_value(value, opts),
None => get_empty_style(&opts.style_computer),
None => get_empty_style(
opts.config.table.missing_value_symbol.clone(),
&opts.style_computer,
),
},
value => get_string_value(value, opts),
}