The next commit wants to add a conditional default for styled underlines.
Due to various incompatibilities in terminals, our best option seems to ask
the terminal.
Today we can make XTGETTCAP queries using something like
printf '\eP+q5373\e\\' # Su
printf '\e[0c'
while read -n 1
...
end
This doesn't seem safe because builtin read might consume other data written
by the terminal such as keyboard input.
Avoid this problem by providing it as a builtin that can enqueue unrelated
input and process it after the query has been answered.
For the same reason, add a builtin to query for XTVERSION; this allows us
to add workarounds for specific terminals (example in the next commit).
TODO:
- Naming -- maybe add a level of nesting:
status query-terminal xtgettcap
status query-terminal xtversion
# Possible future additions:
status query-terminal os-name
status query-terminal cursor-position
or "status query-xtgettcap".
We could also hide the exact protocol by saying
"status query terminfo-capability".
Note that xtgettcap, xtversion and os-name are expected to always give the
same results throughout the lifetime of the fish process. Keep caching
XTVERSION as before, though that's probably not needed.
Future work:
XTGETTCAP potentially supports all of terminfo: boolean, numeric and string
capabilities. Today we have no use beyond checking for presence/absence of
a capabilty. If we ever need more, we can use stdout.