From cf1a53143c3db36dfe0ef71c60fc9cd8c5592b42 Mon Sep 17 00:00:00 2001 From: Tyarel8 <98483313+Tyarel8@users.noreply.github.com> Date: Fri, 13 Jun 2025 23:24:40 +0200 Subject: [PATCH] feat(ansi): use `_` in short name and rst -> reset (#15907) # Description I've noticed that unlike everything else in nushell the output of `ansi --list` has a column named `short name` instead of `short_name`, so I changed it. While I was at it, I also added a shortname `rst` to `reset` since it is often used. # User-Facing Changes Changed the column name of `ansi --list` from `short name` to `short_name` --- crates/nu-command/src/platform/ansi/ansi_.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/nu-command/src/platform/ansi/ansi_.rs b/crates/nu-command/src/platform/ansi/ansi_.rs index 43bb15add0..3016a6bdeb 100644 --- a/crates/nu-command/src/platform/ansi/ansi_.rs +++ b/crates/nu-command/src/platform/ansi/ansi_.rs @@ -435,7 +435,7 @@ static CODE_LIST: LazyLock> = LazyLock::new(|| { vec![ AnsiCode { short_name: Some("h"), long_name: "attr_hidden", code: Style::new().hidden().prefix().to_string()}, AnsiCode { short_name: Some("s"), long_name: "attr_strike", code: Style::new().strikethrough().prefix().to_string()}, - AnsiCode{ short_name: None, long_name: "reset", code: "\x1b[0m".to_owned()}, + AnsiCode{ short_name: Some("rst"), long_name: "reset", code: "\x1b[0m".to_owned()}, // Reference for ansi codes https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797 // Another good reference http://ascii-table.com/ansi-escape-sequences.php @@ -633,6 +633,11 @@ Operating system commands: example: r#"$"(ansi --escape '3;93;41m')Hello(ansi reset)" # italic bright yellow on red background"#, result: Some(Value::test_string("\u{1b}[3;93;41mHello\u{1b}[0m")), }, + Example { + description: "Use simple hex string", + example: r#"$"(ansi '#4169E1')Hello(ansi reset)" # royal blue foreground color"#, + result: Some(Value::test_string("\u{1b}[38;2;65;105;225mHello\u{1b}[0m")), + }, Example { description: "Use structured escape codes", example: r#"let bold_blue_on_red = { # `fg`, `bg`, `attr` are the acceptable keys, all other keys are considered invalid and will throw errors. @@ -874,13 +879,13 @@ fn generate_ansi_code_list( record! { "name" => name, "preview" => preview, - "short name" => short_name, + "short_name" => short_name, "code" => code, } } else { record! { "name" => name, - "short name" => short_name, + "short_name" => short_name, "code" => code, } };