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:
Douglas 2025-02-08 16:23:51 -05:00 committed by GitHub
parent 5a7707cb52
commit 26897b287c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 1 deletions

View File

@ -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()

View File

@ -8,5 +8,5 @@ fn test_char_list_outputs_table() {
"#
));
assert_eq!(actual.out, "107");
assert_eq!(actual.out, "113");
}

View File

@ -1,2 +1,3 @@
mod ansi_;
mod char_;
mod kill;