terminfo

From Noah.org
Revision as of 19:20, 11 April 2014 by Root (Talk | contribs) (translate tput commands to echo strings)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Terminfo and Termcap

Don't use termcap; it's the old system. Use terminfo.

translate tput commands to echo strings

tput-to-str(){ infocmp -E | sed -n -e "/_s_$@/s/^.*\"\(.*\)\";.*/\1/p"; }

You can use it like this:

echo -n -e $(tput-to-str cuu1)

which should be the same as this

tput cuu1

which might seem a bit useless if you already have tput available. Where it is more useful is in situations where you want to pregenerate echo strings for an embedded system that might not have terminfo and curses installed.

This version extracts the characters that tput actually writes, but the string quoting format is not standard C or shell (echo -n -e won't work).

tput-to-str(){( strace -s 1000 -e write tput $@ 2>&2 2>&1 ) | grep -o '"[^"]*"';}