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

@ -74,13 +74,16 @@ impl Command for Explore {
let mut config = nu_config.explore.clone();
prepare_default_config(&mut config);
update_config(&mut config, show_index, show_head);
include_nu_config(&mut config, &style_computer);
let show_banner = is_need_banner(&config).unwrap_or(true);
let exit_esc = is_need_esc_exit(&config).unwrap_or(true);
let style = style_from_config(&config);
let mut config = PagerConfig::new(nu_config, &style_computer, config);
let lscolors = nu_explore::util::create_lscolors(engine_state, stack);
let mut config = PagerConfig::new(nu_config, &style_computer, &lscolors, config);
config.style = style;
config.reverse = is_reverse;
config.peek_value = peek_value;
@ -246,6 +249,7 @@ fn prepare_default_config(config: &mut HashMap<String, Value>) {
config.insert(String::from("status"), map_into_value(hm));
}
{
let mut hm = config
.get("table")
@ -322,8 +326,7 @@ fn insert_style(map: &mut HashMap<String, Value>, key: &str, value: Style) {
}
let value = nu_color_config::NuStyle::from(value);
if let Ok(val) = nu_json::to_string(&value) {
if let Ok(val) = nu_json::to_string_raw(&value) {
map.insert(String::from(key), Value::string(val, Span::unknown()));
}
}
@ -368,3 +371,39 @@ fn convert_json_value_into_value(value: nu_json::Value) -> Value {
}
}
}
fn include_nu_config(config: &mut HashMap<String, Value>, style_computer: &StyleComputer) {
let line_color = lookup_color(style_computer, "separator");
if line_color != nu_ansi_term::Style::default() {
{
let mut map = config
.get("table")
.and_then(parse_hash_map)
.unwrap_or_default();
insert_style(&mut map, "split_line", line_color);
config.insert(String::from("table"), map_into_value(map));
}
{
let mut map = config
.get("try")
.and_then(parse_hash_map)
.unwrap_or_default();
insert_style(&mut map, "border_color", line_color);
config.insert(String::from("try"), map_into_value(map));
}
{
let mut map = config
.get("config")
.and_then(parse_hash_map)
.unwrap_or_default();
insert_style(&mut map, "border_color", line_color);
config.insert(String::from("config"), map_into_value(map));
}
}
}
fn lookup_color(style_computer: &StyleComputer, key: &str) -> nu_ansi_term::Style {
style_computer.compute(key, &Value::nothing(Span::unknown()))
}