Fix issue with the char --list
command output alignment broken by specified characters (#13395)
This commit is contained in:
parent
5db57abc7d
commit
80811f7275
|
@ -3,6 +3,7 @@ use nu_engine::command_prelude::*;
|
||||||
|
|
||||||
use nu_protocol::Signals;
|
use nu_protocol::Signals;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
// Character used to separate directories in a Path Environment variable on windows is ";"
|
// Character used to separate directories in a Path Environment variable on windows is ";"
|
||||||
#[cfg(target_family = "windows")]
|
#[cfg(target_family = "windows")]
|
||||||
|
@ -149,6 +150,24 @@ static CHAR_MAP: Lazy<IndexMap<&'static str, String>> = Lazy::new(|| {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
static NO_OUTPUT_CHARS: Lazy<HashSet<&'static str>> = 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 {
|
impl Command for Char {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"char"
|
"char"
|
||||||
|
@ -297,6 +316,11 @@ fn generate_character_list(signals: Signals, call_span: Span) -> PipelineData {
|
||||||
CHAR_MAP
|
CHAR_MAP
|
||||||
.iter()
|
.iter()
|
||||||
.map(move |(name, s)| {
|
.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(
|
let unicode = Value::string(
|
||||||
s.chars()
|
s.chars()
|
||||||
.map(|c| format!("{:x}", c as u32))
|
.map(|c| format!("{:x}", c as u32))
|
||||||
|
@ -306,7 +330,7 @@ fn generate_character_list(signals: Signals, call_span: Span) -> PipelineData {
|
||||||
);
|
);
|
||||||
let record = record! {
|
let record = record! {
|
||||||
"name" => Value::string(*name, call_span),
|
"name" => Value::string(*name, call_span),
|
||||||
"character" => Value::string(s, call_span),
|
"character" => character,
|
||||||
"unicode" => unicode,
|
"unicode" => unicode,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user