mirror of
https://github.com/nushell/nushell.git
synced 2025-08-15 04:32:37 +02:00
nu-explore/ Fix configuration issues (#7520)
close #7518 Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
use std::io::Result;
|
||||
use std::{collections::HashMap, io::Result};
|
||||
|
||||
use nu_protocol::{
|
||||
engine::{EngineState, Stack},
|
||||
@ -7,7 +7,7 @@ use nu_protocol::{
|
||||
use tui::layout::Rect;
|
||||
|
||||
use crate::{
|
||||
nu_common::try_build_table,
|
||||
nu_common::{try_build_table, NuSpan},
|
||||
pager::Frame,
|
||||
util::map_into_value,
|
||||
views::{Layout, Preview, View, ViewConfig},
|
||||
@ -128,10 +128,57 @@ impl ConfigView {
|
||||
fn create_output_string(&mut self, config: ViewConfig) -> String {
|
||||
match self.format {
|
||||
ConfigFormat::Table => {
|
||||
let value = map_into_value(config.config.clone());
|
||||
let mut m = config.config.clone();
|
||||
convert_styles(&mut m);
|
||||
|
||||
let value = map_into_value(m);
|
||||
try_build_table(None, config.nu_config, config.style_computer, value)
|
||||
}
|
||||
ConfigFormat::Nu => nu_json::to_string(&config.config).unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_styles(m: &mut HashMap<String, Value>) {
|
||||
for value in m.values_mut() {
|
||||
convert_styles_value(value);
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_styles_value(value: &mut Value) {
|
||||
match value {
|
||||
Value::String { val, .. } => {
|
||||
if let Some(v) = convert_style_from_string(val) {
|
||||
*value = v;
|
||||
}
|
||||
}
|
||||
Value::List { vals, .. } => {
|
||||
for value in vals {
|
||||
convert_styles_value(value);
|
||||
}
|
||||
}
|
||||
Value::Record { vals, .. } => {
|
||||
for value in vals {
|
||||
convert_styles_value(value);
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_style_from_string(s: &str) -> Option<Value> {
|
||||
let style = nu_json::from_str::<nu_color_config::NuStyle>(s).ok()?;
|
||||
let cols = vec![String::from("bg"), String::from("fg"), String::from("attr")];
|
||||
|
||||
let vals = vec![
|
||||
Value::string(style.bg.unwrap_or_default(), NuSpan::unknown()),
|
||||
Value::string(style.fg.unwrap_or_default(), NuSpan::unknown()),
|
||||
Value::string(style.attr.unwrap_or_default(), NuSpan::unknown()),
|
||||
];
|
||||
|
||||
Some(Value::Record {
|
||||
cols,
|
||||
vals,
|
||||
span: NuSpan::unknown(),
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user