Pádraig Brady <[email protected]> writes:
> * src/ls.c (quote_name): Use ST (ESC \) rather than BEL,
> as that's the only terminator mentioned in at least
> ECMA-48, DEC STD 070, and EK-VT520-RM.
> * NEWS: Mention the change in behavior.
> * tests/ls/hyperlink.sh: Adjust accordingly.
>
> Suggested by Egmont Koblinger.
> ---
> NEWS | 3 +++
> src/ls.c | 4 ++--
> tests/ls/hyperlink.sh | 4 ++--
> 3 files changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/NEWS b/NEWS
> index e91c4f760..b88f721e0 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -65,6 +65,9 @@ GNU coreutils NEWS -*-
> outline -*-
> 'fmt' -w,--width no longer includes '\n' in the width of a line.
> I.e., the specified width is interpreted to be an _inclusive_ maximum.
>
> + 'ls --hyperlink' now uses more standard format hyperlinks.
> + '\e\' (ST) is now used as a delimiter, instead of '\a' (BEL).
> +
> 'ptx' -t is no longer a no-op, and now sets the default width to 100
> columns.
>
> 'timeout' now honors ignored signals and will not propagate them. E.g.,
> diff --git a/src/ls.c b/src/ls.c
> index 102ef4a3f..5d87a1c36 100644
> --- a/src/ls.c
> +++ b/src/ls.c
> @@ -4723,7 +4723,7 @@ quote_name (char const *name, struct quoting_options
> const *options,
> For example since ls is outputting a dense block of URIs
> it would be best to not underline by default, and only
> do so upon hover etc. */
> - printf ("\033]8;;file://%s%s%s\a", h, *n == '/' ? "" : "/", n);
> + printf ("\033]8;;file://%s%s%s\e\\", h, *n == '/' ? "" : "/", n);
> free (h);
> free (n);
> }
> @@ -4740,7 +4740,7 @@ quote_name (char const *name, struct quoting_options
> const *options,
>
> if (absolute_name)
> {
> - fputs ("\033]8;;\a", stdout);
> + fputs ("\033]8;;\e\\", stdout);
> if (skip_quotes)
> putchar (*(buf + len - 1));
> }
> diff --git a/tests/ls/hyperlink.sh b/tests/ls/hyperlink.sh
> index 3fd6c4f24..5f813e3ee 100755
> --- a/tests/ls/hyperlink.sh
> +++ b/tests/ls/hyperlink.sh
> @@ -31,7 +31,7 @@ encode() {
> ls_encoded() {
> ef=$(encode "$1")
> echo "$ef" | grep 'dir$' >/dev/null && dir=: || dir=''
> - printf '\033]8;;file:///%s\a%s\033]8;;\a%s\n' \
> + printf '\033]8;;file:///%s\e\\%s\033]8;;\e\\%s\n' \
> "$ef" "$1" "$dir"
> }
>
> @@ -51,7 +51,7 @@ for f in 'an#chor' 'back\slash' 'col:on'
> 'encoded%3Fquestion' \
> done
> )
> ln -s testdir testdirl || framework_failure_
> -(cat exp.t && printf '\n' && sed 's/[^\/]testdir/&l/' exp.t) > exp \
> +(cat exp.t && printf '\n' && sed 's|[^/]testdir|&l|' exp.t) > exp \
> || framework_failure_
> ls --hyper testdir testdirl >out.t || fail=1
> strip_host_and_path <out.t >out || framework_failure_
Taking a look at the other GNU programs that implement hyperlinks for
terminals [1]:
* Emacs accepts both (see lisp/ansi-osc.el).
* Groff emits \e.
* GCC emits \a, the rationale can be seen in a comment (bear in mind the
commit was from 2019 so things may have changed):
$ git diff ae169f9e4cbb5a1f1767106d86f322d166d5189d^
ae169f9e4cbb5a1f1767106d86f322d166d5189d
[...]
- > OSC (operating system command) is typically ESC ]. */
+ > OSC (operating system command) is typically ESC ].
+
+ Use BEL instead of ST, as that is currently rendered better in some
+ terminal emulators that don't support OSC 8, like konsole. */
* wget2 emits \e.
Not sure if you knew that already or if it makes you reconsider, just
thought it was worth looking into.
I use Gnome terminal which supports both, so I do not feel very strongly
about the change either way. :)
Also, isn't \e is a GCC extension and not standardized, see C23 § 5.2.3.
I assume it is widly supported, but am not 100% sure on that. You might
want to use \033 instead.
Collin
[1] https://github.com/Alhadis/OSC8-Adoption?tab=readme-ov-file