[PATCH] docs: use standard SGR format in xterm-true-color

11 views
Skip to first unread message

Andrea Pappacoda

unread,
Dec 31, 2024, 4:29:12 AM12/31/24
to vim...@vim.org, Andrea Pappacoda
By default, Vim uses the non-standard, but widely supported, legacy
xterm/Konsole format for setting "direct colors" with set setaf and
setbf escape codes, which use semicolons as separators.

The documentation for xterm-true-color mentions that, as an alternative,
users can set alternative sequences that use colons instead of
semicolons. This format, though, isn't standard and it is unclear how
widely supported it is; it was added by xterm patch 282 due to a
misinterpretation of the ISO 8613-6 (ITU T.416) standard, and was later
changed to the format suggested by this patch, which is the one
specified in the standard.

Today, looking at ncurses' [terminfo], it seems that all terminal
emulators use either the standard format (named "xterm+direct" in the
terminfo source) or the legacy format (named "xterm+indirect" in the
terminfo source).

Hence, I believe it makes sense to align the docs with reality.

If you're interested in the story of this escape sequence, I'd recommend
reading
<https://invisible-island.net/ncurses/ncurses.faq.html#xterm_16MegaColors>.

[terminfo]: https://invisible-island.net/ncurses/terminfo.ti.html
---
runtime/doc/term.txt | 9 +++++----
src/libvterm/t/30state_pen.test | 4 ++--
2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/runtime/doc/term.txt b/runtime/doc/term.txt
index d930dd33e..49f004826 100644
--- a/runtime/doc/term.txt
+++ b/runtime/doc/term.txt
@@ -688,10 +688,11 @@ The default values are set like this: >
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"

-Some terminals accept the same sequences, but with all semicolons replaced by
-colons (this is actually more compatible, but less widely supported): >
- let &t_8f = "\<Esc>[38:2:%lu:%lu:%lum"
- let &t_8b = "\<Esc>[48:2:%lu:%lu:%lum"
+Some terminals accept similar sequences, with semicolons replaced by colons
+and an extra colon after the number 2 (this is conformant to the ISO 8613-6
+standard, but less widely supported): >
+ let &t_8f = "\<Esc>[38:2::%lu:%lu:%lum"
+ let &t_8b = "\<Esc>[48:2::%lu:%lu:%lum"

These options contain printf strings, with |printf()| (actually, its C
equivalent hence `l` modifier) invoked with the t_ option value and three
diff --git a/src/libvterm/t/30state_pen.test b/src/libvterm/t/30state_pen.test
index 1a6cd01dd..f237394eb 100644
--- a/src/libvterm/t/30state_pen.test
+++ b/src/libvterm/t/30state_pen.test
@@ -82,7 +82,7 @@ PUSH "\e[34m"
?pen foreground = idx(4)
PUSH "\e[91m"
?pen foreground = idx(9)
-PUSH "\e[38:2:10:20:30m"
+PUSH "\e[38:2::10:20:30m"
?pen foreground = rgb(10,20,30)
PUSH "\e[38:5:1m"
?pen foreground = idx(1)
@@ -98,7 +98,7 @@ PUSH "\e[44m"
?pen background = idx(4)
PUSH "\e[101m"
?pen background = idx(9)
-PUSH "\e[48:2:10:20:30m"
+PUSH "\e[48::2:10:20:30m"
?pen background = rgb(10,20,30)
PUSH "\e[48:5:1m"
?pen background = idx(1)
--
2.45.2

Christian Brabandt

unread,
Dec 31, 2024, 5:30:39 AM12/31/24
to vim...@googlegroups.com, vim...@vim.org

On Sun, 29 Dec 2024, 'Andrea Pappacoda' via vim_dev wrote:

> By default, Vim uses the non-standard, but widely supported, legacy
> xterm/Konsole format for setting "direct colors" with set setaf and
> setbf escape codes, which use semicolons as separators.
>
> The documentation for xterm-true-color mentions that, as an alternative,
> users can set alternative sequences that use colons instead of
> semicolons. This format, though, isn't standard and it is unclear how
> widely supported it is; it was added by xterm patch 282 due to a
> misinterpretation of the ISO 8613-6 (ITU T.416) standard, and was later
> changed to the format suggested by this patch, which is the one
> specified in the standard.
>
> Today, looking at ncurses' [terminfo], it seems that all terminal
> emulators use either the standard format (named "xterm+direct" in the
> terminfo source) or the legacy format (named "xterm+indirect" in the
> terminfo source).
>
> Hence, I believe it makes sense to align the docs with reality.
>
> If you're interested in the story of this escape sequence, I'd recommend
> reading
> <https://invisible-island.net/ncurses/ncurses.faq.html#xterm_16MegaColors>.
>
> [terminfo]: https://invisible-island.net/ncurses/terminfo.ti.html

For the interested reader, this was handled via:
https://github.com/vim/vim/pull/16350

Thanks,
Christian
--
A method of solution is perfect if we can forsee from the start,
and even prove, that following that method we shall attain our aim.
-- Leibnitz
Reply all
Reply to author
Forward
0 new messages