mirror of
https://github.com/nushell/nushell.git
synced 2025-06-19 00:17:02 +02:00
Adds platform agnostic EoL separator to char
command (#15059)
Adds `char eol`, `char line_sep`, and `char lsep` (synonyms) to represent the platform specific line ending character(s).
This commit is contained in:
parent
5a7707cb52
commit
26897b287c
@ -12,6 +12,13 @@ const ENV_PATH_SEPARATOR_CHAR: char = ';';
|
||||
#[cfg(not(target_family = "windows"))]
|
||||
const ENV_PATH_SEPARATOR_CHAR: char = ':';
|
||||
|
||||
// Character used to separate directories in a Path Environment variable on windows is ";"
|
||||
#[cfg(target_family = "windows")]
|
||||
const LINE_SEPARATOR_CHAR: &str = "\r\n";
|
||||
// Character used to separate directories in a Path Environment variable on linux/mac/unix is ":"
|
||||
#[cfg(not(target_family = "windows"))]
|
||||
const LINE_SEPARATOR_CHAR: char = '\n';
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Char;
|
||||
|
||||
@ -59,6 +66,10 @@ static CHAR_MAP: LazyLock<IndexMap<&'static str, String>> = LazyLock::new(|| {
|
||||
"path_sep" => std::path::MAIN_SEPARATOR.to_string(),
|
||||
"psep" => std::path::MAIN_SEPARATOR.to_string(),
|
||||
"separator" => std::path::MAIN_SEPARATOR.to_string(),
|
||||
"eol" => LINE_SEPARATOR_CHAR.to_string(),
|
||||
"lsep" => LINE_SEPARATOR_CHAR.to_string(),
|
||||
"line_sep" => LINE_SEPARATOR_CHAR.to_string(),
|
||||
"lsep" => '\n'.to_string(),
|
||||
"esep" => ENV_PATH_SEPARATOR_CHAR.to_string(),
|
||||
"env_sep" => ENV_PATH_SEPARATOR_CHAR.to_string(),
|
||||
"tilde" => '~'.to_string(), // ~
|
||||
@ -163,6 +174,9 @@ static NO_OUTPUT_CHARS: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
|
||||
"crlf",
|
||||
"bel",
|
||||
"backspace",
|
||||
"lsep",
|
||||
"line_sep",
|
||||
"eol",
|
||||
]
|
||||
.into_iter()
|
||||
.collect()
|
||||
|
@ -8,5 +8,5 @@ fn test_char_list_outputs_table() {
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "107");
|
||||
assert_eq!(actual.out, "113");
|
||||
}
|
||||
|
@ -1,2 +1,3 @@
|
||||
mod ansi_;
|
||||
mod char_;
|
||||
mod kill;
|
||||
|
Loading…
x
Reference in New Issue
Block a user