To avoid a subshell, what are the ANSI escape equivalents of tput sgr0 for an ANSI-compatible terminal?
Asked
Active
Viewed 5,603 times
1 Answers
12
You could answer that by looking at the output of infocmp:
using the -1 option to print one capability per line for a given setting of TERM (i.e., "ansi"), simplifying a grep:
infocmp -1 ansi |grep sgr0=
and seeing (for example)
sgr0=\E[0;10m,
which tells you that you could do
printf '\033[0;10m'
to get the same effect as
tput -T ansi sgr0
But you're not using ANSI, but rather some particular terminal, and though the ones you're using are similar, not all are identical. It's more likely that your TERM variable is set to something like "xterm", which (omitting the terminal type) gives
sgr0=\E(B\E[m,
The common part is the \E[m, which is the terminfo syntax for \033[m. The other characters in each sequence are resetting the alternate character set (and can depend on the terminal type).
Thomas Dickey
- 75,040
- 9
- 171
- 268
-
Is `ansi` an option? – rosshjb Aug 18 '20 at 12:00
-
1**`-T ansi`** is an option, telling **`tput`** which terminal description to use. – Thomas Dickey Aug 18 '20 at 18:29
-
Please consider explaining the entire command, e.g. `-1 ansi`, so I don't have to look it up or test personally to see that results in each variable printing on its own line. – Sinjai Jan 18 '21 at 04:55