mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
ls: set default quoting style to literal when not TTY (#5553)
* ls: set default quoting style to literal if output is not TTY * tests/ls: Fix quoting tests that now run with Literal as default * ls: Fix formatting/linting/spelling issues * tests/ls: Fix windows escaped tests
This commit is contained in:
parent
7333573361
commit
673093f842
2 changed files with 16 additions and 10 deletions
|
@ -642,7 +642,9 @@ fn extract_quoting_style(options: &clap::ArgMatches, show_control: bool) -> Quot
|
||||||
QuotingStyle::C {
|
QuotingStyle::C {
|
||||||
quotes: quoting_style::Quotes::Double,
|
quotes: quoting_style::Quotes::Double,
|
||||||
}
|
}
|
||||||
} else if options.get_flag(options::DIRED) {
|
} else if options.get_flag(options::DIRED) || !std::io::stdout().is_terminal() {
|
||||||
|
// By default, `ls` uses Literal quoting when
|
||||||
|
// writing to a non-terminal file descriptor
|
||||||
QuotingStyle::Literal { show_control }
|
QuotingStyle::Literal { show_control }
|
||||||
} else {
|
} else {
|
||||||
// TODO: use environment variable if available
|
// TODO: use environment variable if available
|
||||||
|
|
|
@ -2472,13 +2472,16 @@ fn test_ls_quoting_style() {
|
||||||
{
|
{
|
||||||
at.touch("one\ntwo");
|
at.touch("one\ntwo");
|
||||||
at.touch("one\\two");
|
at.touch("one\\two");
|
||||||
// Default is shell-escape
|
// Default is literal, when stdout is not a TTY.
|
||||||
|
// Otherwise, it is shell-escape
|
||||||
scene
|
scene
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.arg("--hide-control-chars")
|
.arg("--hide-control-chars")
|
||||||
.arg("one\ntwo")
|
.arg("one\ntwo")
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_only("'one'$'\\n''two'\n");
|
.stdout_only("one?two\n");
|
||||||
|
// TODO: TTY-expected output, find a way to check this as well
|
||||||
|
// .stdout_only("'one'$'\\n''two'\n");
|
||||||
|
|
||||||
for (arg, correct) in [
|
for (arg, correct) in [
|
||||||
("--quoting-style=literal", "one?two"),
|
("--quoting-style=literal", "one?two"),
|
||||||
|
@ -2565,7 +2568,9 @@ fn test_ls_quoting_style() {
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.arg("one two")
|
.arg("one two")
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_only("'one two'\n");
|
.stdout_only("one two\n");
|
||||||
|
// TODO: TTY-expected output
|
||||||
|
// .stdout_only("'one two'\n");
|
||||||
|
|
||||||
for (arg, correct) in [
|
for (arg, correct) in [
|
||||||
("--quoting-style=literal", "one two"),
|
("--quoting-style=literal", "one two"),
|
||||||
|
@ -2628,7 +2633,9 @@ fn test_ls_quoting_and_color() {
|
||||||
.arg("--color")
|
.arg("--color")
|
||||||
.arg("one two")
|
.arg("one two")
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_only("'one two'\n");
|
.stdout_only("one two\n");
|
||||||
|
// TODO: TTY-expected output
|
||||||
|
// .stdout_only("'one two'\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -3160,11 +3167,8 @@ fn test_ls_path() {
|
||||||
.stdout_is(expected_stdout);
|
.stdout_is(expected_stdout);
|
||||||
|
|
||||||
let abs_path = format!("{}/{}", at.as_string(), path);
|
let abs_path = format!("{}/{}", at.as_string(), path);
|
||||||
let expected_stdout = if cfg!(windows) {
|
let expected_stdout = format!("{abs_path}\n");
|
||||||
format!("\'{abs_path}\'\n")
|
|
||||||
} else {
|
|
||||||
format!("{abs_path}\n")
|
|
||||||
};
|
|
||||||
scene.ucmd().arg(&abs_path).run().stdout_is(expected_stdout);
|
scene.ucmd().arg(&abs_path).run().stdout_is(expected_stdout);
|
||||||
|
|
||||||
let expected_stdout = format!("{path}\n{file1}\n");
|
let expected_stdout = format!("{path}\n{file1}\n");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue