remove config use_grid_icons, move to parameter of grid command (#13788)

# Description

After looking at #13751 I noticed that the config setting
`use_grid_icons` seems out of place. So, I removed it from the config
and made it a parameter to the `grid` command.
This commit is contained in:
Darren Schroeder 2024-09-05 18:25:43 -05:00 committed by GitHub
parent 870eb2530c
commit d0c2adabf7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 27 additions and 16 deletions

View file

@ -33,6 +33,11 @@ impl Command for Griddle {
Some('w'),
)
.switch("color", "draw output with color", Some('c'))
.switch(
"icons",
"draw output with icons (assumes nerd font is used)",
Some('i'),
)
.named(
"separator",
SyntaxShape::String,
@ -61,12 +66,13 @@ prints out the list properly."#
let width_param: Option<i64> = call.get_flag(engine_state, stack, "width")?;
let color_param: bool = call.has_flag(engine_state, stack, "color")?;
let separator_param: Option<String> = call.get_flag(engine_state, stack, "separator")?;
let icons_param: bool = call.has_flag(engine_state, stack, "icons")?;
let config = &stack.get_config(engine_state);
let env_str = match stack.get_env_var(engine_state, "LS_COLORS") {
Some(v) => Some(env_to_string("LS_COLORS", &v, engine_state, stack)?),
None => None,
};
let use_grid_icons = config.use_grid_icons;
let use_color: bool = color_param && config.use_ansi_coloring;
let cwd = engine_state.cwd(Some(stack))?;
@ -82,7 +88,7 @@ prints out the list properly."#
use_color,
separator_param,
env_str,
use_grid_icons,
icons_param,
cwd.as_ref(),
)?)
} else {
@ -100,7 +106,7 @@ prints out the list properly."#
use_color,
separator_param,
env_str,
use_grid_icons,
icons_param,
cwd.as_ref(),
)?)
} else {
@ -123,7 +129,7 @@ prints out the list properly."#
use_color,
separator_param,
env_str,
use_grid_icons,
icons_param,
cwd.as_ref(),
)?)
}
@ -162,6 +168,11 @@ prints out the list properly."#
example: "[[name patch]; [0.1.0 false] [0.1.1 true] [0.2.0 false]] | grid",
result: Some(Value::test_string("0.1.0 │ 0.1.1 │ 0.2.0\n")),
},
Example {
description: "Render a table with 'name' column in it to a grid with icons and colors",
example: "[[name patch]; [Cargo.toml false] [README.md true] [SECURITY.md false]] | grid --icons --color",
result: None,
},
]
}
}
@ -174,7 +185,7 @@ fn create_grid_output(
use_color: bool,
separator_param: Option<String>,
env_str: Option<String>,
use_grid_icons: bool,
icons_param: bool,
cwd: &Path,
) -> Result<PipelineData, ShellError> {
let ls_colors = get_ls_colors(env_str);
@ -201,7 +212,7 @@ fn create_grid_output(
// only output value if the header name is 'name'
if header == "name" {
if use_color {
if use_grid_icons {
if icons_param {
let no_ansi = nu_utils::strip_ansi_unlikely(&value);
let path = cwd.join(no_ansi.as_ref());
let icon = icon_for_file(&path, call.head)?;
@ -232,6 +243,14 @@ fn create_grid_output(
cell.alignment = Alignment::Left;
grid.add(cell);
}
} else if icons_param {
let no_ansi = nu_utils::strip_ansi_unlikely(&value);
let path = cwd.join(no_ansi.as_ref());
let icon = icon_for_file(&path, call.head)?;
let item = format!("{} {}", String::from(icon), value);
let mut cell = Cell::from(item);
cell.alignment = Alignment::Left;
grid.add(cell);
} else {
let mut cell = Cell::from(value);
cell.alignment = Alignment::Left;

File diff suppressed because one or more lines are too long

View file

@ -47,7 +47,6 @@ pub struct Config {
pub table: TableConfig,
pub ls: LsConfig,
pub color_config: HashMap<String, Value>,
pub use_grid_icons: bool,
pub footer_mode: FooterMode,
pub float_precision: i64,
pub recursion_limit: i64,
@ -104,7 +103,6 @@ impl Default for Config {
cursor_shape: CursorShapeConfig::default(),
color_config: HashMap::new(),
use_grid_icons: true,
footer_mode: FooterMode::RowCount(25),
float_precision: 2,
buffer_editor: Value::nothing(Span::unknown()),
@ -526,9 +524,6 @@ impl Value {
*value = config.color_config.clone().into_value(span);
}
}
"use_grid_icons" => {
process_bool_config(value, &mut errors, &mut config.use_grid_icons);
}
"footer_mode" => {
process_string_enum(
&mut config.footer_mode,

View file

@ -227,7 +227,6 @@ $env.config = {
}
color_config: $dark_theme # if you want a more interesting theme, you can replace the empty record with `$dark_theme`, `$light_theme` or another custom record
use_grid_icons: true
footer_mode: 25 # always, never, number_of_rows, auto
float_precision: 2 # the precision for displaying floats in tables
buffer_editor: null # command that will be used to edit the current line buffer with ctrl+o, if unset fallback to $env.EDITOR and $env.VISUAL