I'm writing a wrapper around ack to search for code locally with some additional lines of context piped to a pager.
Here's the wrapper script ackc. Between the different examples, I'll be varying what gets passed to ack as the --pager.
#!/bin/sh ack -C 20 -i \ --pager=most \ --heading \ --break \ --color \ --show-types \ "$@" With less (without the -R) as the pager, almost all of the escape sequences are rendered using the caret notation (don't know what that's called. ^[ is the exception. It is rendered as ESC with inverted background colors (colors not reproduced here).
Here's a sample of the output (produced by ackc with --pager=less and environment variables such as LESS, LESSPIPE etc cleared)
ESC[1;32m.local/lib/python2.7/site-packages/markupsafe/_speedups.cESC[0m ... ESC[1;33m19ESC[0m:#define PY_SSIZE_T_MAX ESC[30;43mINTESC[0m_MAXESC[0mESC[K ESC[1;33m20ESC[0m:#define PY_SSIZE_T_MIN ESC[30;43mINTESC[0m_MINESC[0mESC[K The important escape sequence here is the ^[[K sequence at the end of each line containing a highlighted item. It is handled appropriately by less -R.
.local/lib/python2.7/site-packages/markupsafe/_speedups.c ... 19:#define PY_SSIZE_T_MAX INT_MAX 20:#define PY_SSIZE_T_MIN INT_MIN most, however, does not seem to handle it very well.
.local/lib/python2.7/site-packages/markupsafe/_speedups.c 1-/** ... 19:#define PY_SSIZE_T_MAX INT_MAX^[[K 20:#define PY_SSIZE_T_MIN INT_MIN^[[K It passes through the ^[[K sequence as-is.
This sequence is CSI (n) K -- EL -- Erase in Line. When given no argument, it erases to the end of the line. Presumably this is needed to clear stray bits of background color if the matched term appears at the end of the line.
Is there a reason why most doesn't understand this sequence? Can I configure it to process it correctly?
TERMenvironment variable?tmuxunderlxterminal, which sets theTERMenvironment variable toscreen. It also happens if I run the command not undertmux, in which caseTERMisxterm.^[[Kto thatmostwill understand? It might be possible to extendackto emit different escape sequences so it can cooperate with different pagers.