mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 00:44:57 +02:00
Use IntoValue
in config code (#13751)
# Description Cleans up and refactors the config code using the `IntoValue` macro. Shoutout to @cptpiepmatz for making the macro! # User-Facing Changes Should be none. # After Submitting Somehow refactor the reverse transformation.
This commit is contained in:
@ -23,8 +23,8 @@ pub fn create_nu_table_config(
|
||||
with_index: out.with_index,
|
||||
with_header: out.with_header,
|
||||
split_color: Some(lookup_separator_color(comp)),
|
||||
trim: config.trim_strategy.clone(),
|
||||
header_on_border: config.table_move_header,
|
||||
trim: config.table.trim.clone(),
|
||||
header_on_border: config.table.header_on_separator,
|
||||
expand,
|
||||
}
|
||||
}
|
||||
@ -62,7 +62,8 @@ pub fn error_sign(style_computer: &StyleComputer) -> (String, TextStyle) {
|
||||
}
|
||||
|
||||
pub fn wrap_text(text: &str, width: usize, config: &Config) -> String {
|
||||
string_wrap(text, width, is_cfg_trim_keep_words(config))
|
||||
let keep_words = config.table.trim == TrimStrategy::wrap(true);
|
||||
string_wrap(text, width, keep_words)
|
||||
}
|
||||
|
||||
pub fn get_header_style(style_computer: &StyleComputer) -> TextStyle {
|
||||
@ -163,15 +164,6 @@ fn convert_with_precision(val: &str, precision: usize) -> Result<String, ShellEr
|
||||
Ok(format!("{val_float:.precision$}"))
|
||||
}
|
||||
|
||||
fn is_cfg_trim_keep_words(config: &Config) -> bool {
|
||||
matches!(
|
||||
config.trim_strategy,
|
||||
TrimStrategy::Wrap {
|
||||
try_to_keep_words: true
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
pub fn load_theme(mode: TableMode) -> TableTheme {
|
||||
match mode {
|
||||
TableMode::Basic => TableTheme::basic(),
|
||||
|
@ -36,7 +36,7 @@ fn collapsed_table(
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let indent = (config.table_indent.left, config.table_indent.right);
|
||||
let indent = (config.table.padding.left, config.table.padding.right);
|
||||
let table = table.draw(style_computer, &theme, indent);
|
||||
|
||||
Ok(Some(table))
|
||||
|
@ -26,8 +26,8 @@ impl JustTable {
|
||||
fn create_table(input: &[Value], opts: TableOpts<'_>) -> Result<Option<String>, ShellError> {
|
||||
match table(input, &opts)? {
|
||||
Some(mut out) => {
|
||||
let left = opts.config.table_indent.left;
|
||||
let right = opts.config.table_indent.right;
|
||||
let left = opts.config.table.padding.left;
|
||||
let right = opts.config.table.padding.right;
|
||||
out.table.set_indent(left, right);
|
||||
|
||||
colorize_space(out.table.get_records_mut(), opts.style_computer);
|
||||
@ -59,8 +59,8 @@ fn kv_table(record: &Record, opts: TableOpts<'_>) -> StringResult {
|
||||
|
||||
let mut out = TableOutput::new(table, false, true);
|
||||
|
||||
let left = opts.config.table_indent.left;
|
||||
let right = opts.config.table_indent.right;
|
||||
let left = opts.config.table.padding.left;
|
||||
let right = opts.config.table.padding.right;
|
||||
out.table.set_indent(left, right);
|
||||
|
||||
let table_config =
|
||||
|
@ -67,7 +67,7 @@ impl<'a> TableOpts<'a> {
|
||||
}
|
||||
|
||||
fn has_index(opts: &TableOpts<'_>, headers: &[String]) -> bool {
|
||||
let with_index = match opts.config.table_index_mode {
|
||||
let with_index = match opts.config.table.index_mode {
|
||||
TableIndexMode::Always => true,
|
||||
TableIndexMode::Never => false,
|
||||
TableIndexMode::Auto => headers.iter().any(|header| header == INDEX_COLUMN_NAME),
|
||||
|
Reference in New Issue
Block a user