diff --git a/crates/nu-command/src/strings/char_.rs b/crates/nu-command/src/strings/char_.rs index 7737210254..aa987438d2 100644 --- a/crates/nu-command/src/strings/char_.rs +++ b/crates/nu-command/src/strings/char_.rs @@ -3,6 +3,7 @@ use nu_engine::command_prelude::*; use nu_protocol::Signals; use once_cell::sync::Lazy; +use std::collections::HashSet; // Character used to separate directories in a Path Environment variable on windows is ";" #[cfg(target_family = "windows")] @@ -149,6 +150,24 @@ static CHAR_MAP: Lazy> = Lazy::new(|| { } }); +static NO_OUTPUT_CHARS: Lazy> = Lazy::new(|| { + [ + // If the character is in the this set, we don't output it to prevent + // the broken of `char --list` command table format and alignment. + "newline", + "enter", + "nl", + "line_feed", + "lf", + "cr", + "crlf", + "bel", + "backspace", + ] + .into_iter() + .collect() +}); + impl Command for Char { fn name(&self) -> &str { "char" @@ -297,6 +316,11 @@ fn generate_character_list(signals: Signals, call_span: Span) -> PipelineData { CHAR_MAP .iter() .map(move |(name, s)| { + let character = if NO_OUTPUT_CHARS.contains(name) { + Value::string("", call_span) + } else { + Value::string(s, call_span) + }; let unicode = Value::string( s.chars() .map(|c| format!("{:x}", c as u32)) @@ -306,7 +330,7 @@ fn generate_character_list(signals: Signals, call_span: Span) -> PipelineData { ); let record = record! { "name" => Value::string(*name, call_span), - "character" => Value::string(s, call_span), + "character" => character, "unicode" => unicode, };