forked from extern/nushell
nu-table: Use config color scheme in kv tables and table -e
(#10720)
fix #10712 cc: @fdncred
This commit is contained in:
parent
1f62024a15
commit
4e5a1ced13
@ -30,6 +30,20 @@ pub fn create_nu_table_config(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn nu_value_to_string_colored(val: &Value, cfg: &Config, style: &StyleComputer) -> String {
|
||||||
|
let (mut text, value_style) = nu_value_to_string(val, cfg, style);
|
||||||
|
if let Some(color) = value_style.color_style {
|
||||||
|
text = color.paint(text).to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
if matches!(val, Value::String { .. }) {
|
||||||
|
text = clean_charset(&text);
|
||||||
|
colorize_space_str(&mut text, style);
|
||||||
|
}
|
||||||
|
|
||||||
|
text
|
||||||
|
}
|
||||||
|
|
||||||
pub fn nu_value_to_string(val: &Value, cfg: &Config, style: &StyleComputer) -> NuText {
|
pub fn nu_value_to_string(val: &Value, cfg: &Config, style: &StyleComputer) -> NuText {
|
||||||
let float_precision = cfg.float_precision as usize;
|
let float_precision = cfg.float_precision as usize;
|
||||||
let text = val.into_abbreviated_string(cfg);
|
let text = val.into_abbreviated_string(cfg);
|
||||||
|
@ -9,8 +9,9 @@ use tabled::grid::config::Position;
|
|||||||
use crate::{
|
use crate::{
|
||||||
common::{
|
common::{
|
||||||
create_nu_table_config, error_sign, get_header_style, get_index_style,
|
create_nu_table_config, error_sign, get_header_style, get_index_style,
|
||||||
load_theme_from_config, nu_value_to_string, nu_value_to_string_clean, wrap_text, NuText,
|
load_theme_from_config, nu_value_to_string, nu_value_to_string_clean,
|
||||||
StringResult, TableResult, INDEX_COLUMN_NAME,
|
nu_value_to_string_colored, wrap_text, NuText, StringResult, TableResult,
|
||||||
|
INDEX_COLUMN_NAME,
|
||||||
},
|
},
|
||||||
string_width, NuTable, NuTableCell, TableOpts, TableOutput,
|
string_width, NuTable, NuTableCell, TableOpts, TableOutput,
|
||||||
};
|
};
|
||||||
@ -448,10 +449,10 @@ fn expand_table_value(
|
|||||||
))),
|
))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => Ok(Some((
|
_ => {
|
||||||
value_to_wrapped_string_clean(value, cfg, value_width),
|
let text = value_to_wrapped_string_clean(value, cfg, value_width);
|
||||||
false,
|
Ok(Some((text, false)))
|
||||||
))),
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -607,9 +608,6 @@ fn value_to_wrapped_string(value: &Value, cfg: &Cfg<'_>, value_width: usize) ->
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn value_to_wrapped_string_clean(value: &Value, cfg: &Cfg<'_>, value_width: usize) -> String {
|
fn value_to_wrapped_string_clean(value: &Value, cfg: &Cfg<'_>, value_width: usize) -> String {
|
||||||
wrap_text(
|
let text = nu_value_to_string_colored(value, cfg.opts.config, cfg.opts.style_computer);
|
||||||
&value_to_string_clean(value, cfg),
|
wrap_text(&text, value_width, cfg.opts.config)
|
||||||
value_width,
|
|
||||||
cfg.opts.config,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ use crate::{
|
|||||||
clean_charset, colorize_space,
|
clean_charset, colorize_space,
|
||||||
common::{
|
common::{
|
||||||
create_nu_table_config, get_empty_style, get_header_style, get_index_style,
|
create_nu_table_config, get_empty_style, get_header_style, get_index_style,
|
||||||
get_value_style, NuText, INDEX_COLUMN_NAME,
|
get_value_style, nu_value_to_string_colored, NuText, INDEX_COLUMN_NAME,
|
||||||
},
|
},
|
||||||
NuTable, NuTableCell, StringResult, TableOpts, TableOutput, TableResult,
|
NuTable, NuTableCell, StringResult, TableOpts, TableOutput, TableResult,
|
||||||
};
|
};
|
||||||
@ -47,20 +47,15 @@ fn kv_table(record: &Record, opts: TableOpts<'_>) -> StringResult {
|
|||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
let is_string_value = matches!(value, Value::String { .. });
|
let value = nu_value_to_string_colored(value, opts.config, opts.style_computer);
|
||||||
let mut value = value.into_abbreviated_string(opts.config);
|
|
||||||
if is_string_value {
|
|
||||||
value = clean_charset(&value);
|
|
||||||
}
|
|
||||||
|
|
||||||
let key = NuTableCell::new(column.to_string());
|
let key = NuTableCell::new(column.to_string());
|
||||||
let value = NuTableCell::new(value);
|
let value = NuTableCell::new(value);
|
||||||
|
|
||||||
row.push(key);
|
row.push(key);
|
||||||
row.push(value);
|
row.push(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
colorize_space(&mut data, opts.style_computer);
|
|
||||||
|
|
||||||
let mut table = NuTable::from(data);
|
let mut table = NuTable::from(data);
|
||||||
table.set_index_style(TextStyle::default_field());
|
table.set_index_style(TextStyle::default_field());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user