Not everyone wants -b, but that's the default for a tty, and we don't
currently have an opt out.

To my surprise, -N (despite having the long name --literal) only
disables -b, not -q. There's a separate --show-control-chars (opposite
of --hide-control-chars, which is the long name for -q) for that, so -N
really is just "the opposite of -b".

Since no-one's asked for --show-control-chars yet to my knowledge, I've
not implemented that here.

Also add tests for -b/-q/-N.
---
 tests/ls.test   | 7 +++++++
 toys/posix/ls.c | 7 +++++--
 2 files changed, 12 insertions(+), 2 deletions(-)
From 90737340727058b2b20c970507ad80c9fe5501f0 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <[email protected]>
Date: Thu, 1 Dec 2022 11:31:56 -0800
Subject: [PATCH] ls -N.

Not everyone wants -b, but that's the default for a tty, and we don't
currently have an opt out.

To my surprise, -N (despite having the long name --literal) only
disables -b, not -q. There's a separate --show-control-chars (opposite
of --hide-control-chars, which is the long name for -q) for that, so -N
really is just "the opposite of -b".

Since no-one's asked for --show-control-chars yet to my knowledge, I've
not implemented that here.

Also add tests for -b/-q/-N.
---
 tests/ls.test   | 7 +++++++
 toys/posix/ls.c | 7 +++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/tests/ls.test b/tests/ls.test
index 4856da5c..7ca2b2ca 100755
--- a/tests/ls.test
+++ b/tests/ls.test
@@ -68,5 +68,12 @@ touch lstest/{a,b,c,d,e,f}
 testing "-w test 3" "$IN && ls -Cw 3; $OUT" "a\nb\nc\nd\ne\nf\n" "" ""
 testing "-w test 4" "$IN && ls -Cw 4; $OUT" "a  d\nb  e\nc  f\n" "" ""
 
+rm -rf lstest/*
+touch lstest/'hello 
world'
+testing "default escaping" "$IN && ls; $OUT" "hello 
world\n" "" ""
+testing "-b" "$IN && ls -b; $OUT" 'hello\\ \\rworld\n' "" ""
+testing "-q" "$IN && ls -q; $OUT" 'hello ?world\n' "" ""
+testing "-N" "$IN && ls -q; $OUT" 'hello ?world\n' "" ""
+
 # Removing test dir for cleanup purpose
 rm -rf lstest
diff --git a/toys/posix/ls.c b/toys/posix/ls.c
index 15511059..89dfe67a 100644
--- a/toys/posix/ls.c
+++ b/toys/posix/ls.c
@@ -12,7 +12,7 @@
  *   Posix says the -l date format should vary based on how recent it is
  *   and we do --time-style=long-iso instead
 
-USE_LS(NEWTOY(ls, "(color):;(full-time)(show-control-chars)ZgoACFHLRSabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][!qb]", TOYFLAG_BIN|TOYFLAG_LOCALE))
+USE_LS(NEWTOY(ls, "(color):;(full-time)(show-control-chars)ZgoACFHLNRSabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][!Nqb]", TOYFLAG_BIN|TOYFLAG_LOCALE))
 
 config LS
   bool "ls"
@@ -30,7 +30,7 @@ config LS
     -u  use access time for timestamps -A  list all files but . and ..
     -H  follow command line symlinks   -L  follow symlinks
     -R  recursively list in subdirs    -F  append /dir *exe @sym |FIFO
-    -Z  security context
+    -N  no escaping, even on tty       -Z  security context
 
     output formats:
     -1  list one file per line         -C  columns (sorted vertically)
@@ -518,6 +518,9 @@ void ls_main(void)
     if (TT.color) toys.optflags ^= FLAG_color;
   }
 
+  // -N *doesn't* disable -q; you need --show-control-chars for that.
+  if (FLAG(N)) toys.optflags &= ~FLAG_b;
+
   TT.screen_width = 80;
   if (FLAG(w)) TT.screen_width = TT.w+2;
   else terminal_size(&TT.screen_width, NULL);
-- 
2.39.0.rc0.267.gcb52ba06e7-goog

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to