Difference between revisions of "terminfo"

From Noah.org
Jump to navigationJump to search
m (Created page with 'Category: Engineering = Terminfo and Termcap = Don't use '''termcap'''; it's the old system. Use '''terminfo'''. == translate tput commands to echo strings == <pre> tput-…')
 
 
Line 12: Line 12:
 
You can use it like this:
 
You can use it like this:
 
<pre>
 
<pre>
 
+
echo -n -e $(tput-to-str cuu1)
 +
</pre>
 +
which should be the same as this
 +
<pre>
 +
tput cuu1
 +
</pre>
 +
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).
 
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).

Latest revision as of 19:20, 11 April 2014


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 '"[^"]*"';}