Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programming function keys with tput

Status
Not open for further replies.
Jun 9, 2000
1
0
0
US
Hi there,<br><br>I'm trying to use tput to program a function key.&nbsp;&nbsp;I've read through the man pages on tput and terminfo, but I'm confused as to what the syntax should look like.<br><br>Example:<br>$tput pfkey f11=$(date)<br><br>or<br><br>$tput pfloc f11 &lt;ENTER&gt;<br>&gt;date<br><br>I'd like to put this in my .profile with a different executable, but can't seem to figure it out.<br><br>Any help is appreciated.<br><br>Thanks much!
 
I think tput will let you get the value of the F-key, but not reprogram it.&nbsp;&nbsp;ie, you can read the contents of the terminfo entry, and use those entries, but you can't update the actual terminfo entry.<br><br>From a <FONT FACE=monospace>tput</font> man page on a SCO box here:<br><FONT FACE=monospace><br>&nbsp;&nbsp;&nbsp;&nbsp;tput uses the terminfo database to make the values of<br>&nbsp;&nbsp;&nbsp;&nbsp;terminal-dependent capabilities and information available to the shell<br>&nbsp;&nbsp;&nbsp;&nbsp;(see sh(1)), to initialize or reset the terminal, or return the long<br>&nbsp;&nbsp;&nbsp;&nbsp;name of the requested terminal type. tput outputs a string if the<br>&nbsp;&nbsp;&nbsp;&nbsp;attribute (capability name) is of type string, or an integer if the<br>&nbsp;&nbsp;&nbsp;&nbsp;attribute is of type integer.<br></font><br>and so on... In other words, it's read only.<br><br>So, what you probably need is a new terminfo entry containing your amendments.&nbsp;&nbsp;This is easier to do than it sounds.<br><br>1) Think of a <b>new</b> name for your terminal type.&nbsp;&nbsp;Do not overwrite an existing terminfo entry, in case you have problems.<br><br>2) Use the <FONT FACE=monospace>infocmp</font> command to get the terminfo entry for the terminal type you want to amend.&nbsp;&nbsp;For example:<br><FONT FACE=monospace><br>$ <b>infocmp xterm</b><br>#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Reconstructed via infocmp from file: /usr/share/lib/terminfo/x/xterm<br><b>xterm</b>¦<b>xterm terminal emulator (monochrome)</b>,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;am, km, mir, msgr, xenl, xon,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cols#80, lines#24,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;acsc=aakkllmmjjnnwwvvuuttqqxx, bel=^G, bold=\E[1m,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;clear=\E[H\E[2J, cr=\r, csr=\E[%i%p1%d;%p2%dr,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cub=\E[%p1%dD, cud=\E[%p1%dB, cud1=\n, cuf=\E[%p1%dC,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cuf1=\E[C, cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cuu1=\E[A, dch=\E[%p1%dP, dch1=\E[P, dl=\E[%p1%dM,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dl1=\E[M, ed=\E[J, el=\E[K, home=\E[H, ht=\t, hts=\EH,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ich=\E[%p1%d@, ich1=\E[@, il=\E[%p1%dL, il1=\E[L,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ind=\n, is2=\E7\E[r\E[m\E[?7h\E[?1;3;4;6l\E[4l\E8\E&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;kLFT=\E[d, kRIT=\E[c, kb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nbsp;&nbsp;In the example above, I've highlighted the items that will need changing.<br><br>3) If the terminfo entry is the one you want, re-run the <FONT FACE=monospace>infocmp</font> command again, this time redirecting the output to a new file.&nbsp;&nbsp;For example:<br><FONT FACE=monospace><br>infocmp xterm &gt;myxterm.txt<br></font><br><br>4) Edit the file you just created.&nbsp;&nbsp;Change the &quot;short name&quot; of the terminal (<i>xterm</i> highlighted in the example above), and the description of the terminal (highlighted above immediately following xterm).&nbsp;&nbsp;This will ensure that you create a <i>new</i> terminfo entry.&nbsp;&nbsp;To see what termingo entries already exist, list the contents of <FONT FACE=monospace>/usr/lib/terminfo/<i>x</i></font>, where <i>x</i> is the initial letter of the name you want to use.<br><br>5) Edit the <FONT FACE=monospace>kf11</font> entry to set the value for F11 that you want to use.&nbsp;&nbsp;Then save your changes and exit.<br><br>6) Recompile your new terminfo entry.&nbsp;&nbsp;You need to be root to do this:<br><FONT FACE=monospace><br>tic myxterm.txt<br></font><br>7) Finally, set TERM to be your new terminal name.&nbsp;&nbsp;eg,<br><FONT FACE=monospace><br>export TERM=xterm-new<br></font><br><br>So, if you want to set your F11 key to send the string &quot;date&quot; followed by &quot;&lt;Return&gt;&quot;, change kf11 to be:<br><FONT FACE=monospace><br>kf11=date\r<br></font><br><br>Hope this helps. <p> <br><a href=mailto: > </a><br><a href= > </a><br>--<br>
0 1 - Just my two bits
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top