Add small refactorings

This commit is contained in:
Maxim Zhiburt 2024-12-17 16:47:53 +03:00
parent b5b523f314
commit 25a5fca41d
2 changed files with 11 additions and 6 deletions

View file

@ -1,6 +1,6 @@
use nu_ansi_term::Style;
use nu_color_config::StyleComputer;
use nu_protocol::{Config, Record, Value};
use nu_protocol::{Config, Value};
use nu_utils::SharedCow;
use crate::{
@ -51,7 +51,7 @@ fn colorize_value(value: &mut Value, config: &Config, style_computer: &StyleComp
(header, val)
})
.collect::<Record>(),
.collect(),
);
}
Value::List { vals, .. } => {

View file

@ -60,10 +60,7 @@ fn build_table(
DimensionPriority::Last,
));
// color_config closures for "separator" are just given a null.
let color = style.compute("separator", &Value::nothing(Span::unknown()));
let color = color.paint(" ").to_string();
if let Ok(color) = Color::try_from(color) {
if let Some(color) = get_border_color(style) {
if !is_color_empty(&color) {
return build_table_with_border_color(table, color);
}
@ -348,3 +345,11 @@ impl<R, D> TableOption<R, CompactMultilineConfig, D> for SetBorderColor {
cfg.set_borders_color(borders);
}
}
fn get_border_color(style: &StyleComputer<'_>) -> Option<Color> {
// color_config closures for "separator" are just given a null.
let color = style.compute("separator", &Value::nothing(Span::unknown()));
let color = color.paint(" ").to_string();
let color = Color::try_from(color);
color.ok()
}