infocmp
can help. It writes escape as \E
rather than \e
or ^[
.
For example, to find \e[A
, which is your history-search-backward:
$ infocmp -1x | grep -F '=\E[A,'
cuu1=\E[A,
$ man 5 terminfo | grep ' cuu1 '
cursor_up cuu1 up up one line
Which tells you to press cursor up, a.k.a. up arrow.
Note that you will need the -x
flag (shown above) to display some combinations, e.g. Ctrl+<-.
These extended keys are not part of the standard, so they aren't listed in the terminfo man page, but they are documented in the terminfo file.
Also note that the control sequences vary depending on which terminal you use.
You can get information about a different terminal by using infocmp -1x <terminal>
, e.g. infocmp -1x rxvt
, infocmp -1x putty
, etc.
Once you figure out which one terminfo thinks you have, things will be easier if you set your TERM
variable to match.
Have you got specific operations in mind?
Here is an example of using standout mode, which on many terminals will give a strong visible result:
tput smso; echo hello, world; tput rmso
The tput
tool uses the value of the $TERM
environment variable to determine which escape sequences to output - if any. For example
TERM=xterm
( tput smso; echo hello, world; tput rmso ) | hexdump -C
00000000 1b 5b 37 6d 68 65 6c 6c 6f 2c 20 77 6f 72 6c 64 |.[7mhello, world|
00000010 0a 1b 5b 32 37 6d |..[27m|
TERM=dumb
( tput smso; echo hello, world; tput rmso ) | hexdump -C
00000000 68 65 6c 6c 6f 2c 20 77 6f 72 6c 64 0a |hello, world.|
Interesting characteristic pairs can be found in man 5 terminfo
, some of which are as follows:
- Standout:
smso
and rmso
- Underline:
smul
and rmul
- Blink (yes!):
blink
- Doublewide:
swidm
and rwidm
- Reverse:
rev
- Cancel all:
sgr0
If you want to write bold text, but only if the terminal understands it, then a snippet like this will work
boldOn=$(tput smso)
boldOff=$(tput rmso)
# ...
printf "%s%s%s\n" "$boldOn" 'This message will be in bold, when available' "$boldOff"
Best Answer
The blink feature depends upon the terminal (or terminal emulator). Most terminals you will use accept the control sequences documented in ECMA-48, e.g., VT100-compatible. The control sequence may
Applications usually use a terminal description (terminfo or termcap). If the terminal description does not tell how to blink, then the application will not know either.
If your computer has
infocmp
(for terminfo), that will show the capabilities listed in the terminal description.bash
only looks forblink
— using the termcap name, since it is a termcap application. More generally, terminfo can also describe how to blink usingsgr
(which is not available in termcap descriptions).For example, this is a terminfo description of
vt100
:The corresponding termcap is
(The termcap name for
blink
ismb
, which you can see in the description).So... if you are not seeing blinking text, that could be (a) the terminal itself or (b) the terminal description.
Further reading: