Patch explore 4 (#7517)

ref #7339 - This PR updates explore to take some of the colors from
nushell, namely the line colors and the ls_colors.

note: Not sure why this regression appeared maybe it's a feature or it's
no longer supposed to be supported?

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
This commit is contained in:
Maxim Zhiburt
2022-12-18 17:43:15 +03:00
committed by GitHub
parent 183be911d0
commit 28123841ba
14 changed files with 276 additions and 80 deletions

View File

@ -1,4 +1,7 @@
use crate::nu_style::{color_from_hex, lookup_style};
use crate::{
nu_style::{color_from_hex, lookup_style},
parse_nustyle, NuStyle,
};
use nu_ansi_term::Style;
use nu_protocol::Value;
use std::collections::HashMap;
@ -9,6 +12,8 @@ pub fn lookup_ansi_color_style(s: &str) -> Style {
.ok()
.and_then(|c| c.map(|c| c.normal()))
.unwrap_or_default()
} else if s.starts_with('{') {
color_string_to_nustyle(s.to_string())
} else {
lookup_style(s)
}
@ -36,3 +41,17 @@ pub fn get_color_map(colors: &HashMap<String, Value>) -> HashMap<String, Style>
hm
}
fn color_string_to_nustyle(color_string: String) -> Style {
// eprintln!("color_string: {}", &color_string);
if color_string.is_empty() {
return Style::default();
}
let nu_style = match nu_json::from_str::<NuStyle>(&color_string) {
Ok(s) => s,
Err(_) => return Style::default(),
};
parse_nustyle(nu_style)
}

View File

@ -106,6 +106,7 @@ pub fn color_record_to_nustyle(value: &Value) -> Style {
}
}
}
parse_nustyle(NuStyle { fg, bg, attr })
}