Basically I want to animate my terminal but because the text is too long, I need a pager. Let's just say I want to change my text colour periodically in less. Is it possible?
less supports raw ANSI escapes when the
-r option is used. It also supports Erase in line.
You won't see any animation though. For example:
echo -e "foo\x1b[1G\x1b[2Kbar" > test.ansi less -r test.ansi
Will only print
more does pass on ANSI escapes by default but does not support line editing from what I have tested.
What reacts to the escape sequences is normally the tty (unless the running program sets it not to honor them, in which case the program itself may do so).
more(1) does rather primitive screen rewriting (it is really enough to write out screen length lines, and wait for a keypress), so I'd guess it just passes input through.
less(1) needs to back up, so it needs a more detailed control of the screen.
Clearing the line has only an indirect relationship to changing the terminal colors: if you change the background color, then many terminals (Linux console, rxvt, xterm as well as programs imitating one of those) will color the cleared area of the background using that color.
less does use a few clearing operations, but not
\x1b[2K. Reading the source, it uses several features using the termcap interface. The most relevant parts are described in the terminfo(5) manual page:
clr_bol el1 cb Clear to beginning of line clr_eol el ce clear to end of line (P)
el, respectively. There is no conventional termcap capability
el2, and (unless you tell
less to just pass-through the content of a file using the
less will not send a
The same is true of
more, e.g., as in the
util-linux package: it uses only features from termcap. Unlike
more has no option for sending nonprinting characters directly to the terminal.
If you use the
-R option of
less, you have to keep in mind that it is limited:
less does not know (or care, much) what those escapes do. From the manual page:
Causes "raw" control characters to be displayed. The default is to display control characters using the caret notation; for example, a control-A (octal 001) is displayed as "^A". Warning: when the
-roption is used,
lesscannot keep track of the actual appearance of the screen (since this depends on how the screen responds to each type of control character). Thus, various display problems may result, such as long lines being split in the wrong place.