⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch41_10.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 41] 41.10 Using terminfo Capabilities in Shell Programs </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly &amp; Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly &amp; Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:52:07Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch41_01.htm"TITLE="41. Terminal and Serial Line Settings"><LINKREL="prev"HREF="ch41_09.htm"TITLE="41.9 Commands to Adjust Your Terminal "><LINKREL="next"HREF="ch41_11.htm"TITLE="41.11 How termcap and terminfo Describe Terminals "></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch41_09.htm"TITLE="41.9 Commands to Adjust Your Terminal "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 41.9 Commands to Adjust Your Terminal "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 41<BR>Terminal and Serial Line Settings</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch41_11.htm"TITLE="41.11 How termcap and terminfo Describe Terminals "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 41.11 How termcap and terminfo Describe Terminals "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-6720">41.10 Using terminfo Capabilities in Shell Programs </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46002"></A>The weakness of the technique described in article<ACLASS="xref"HREF="ch41_09.htm"TITLE="Commands to Adjust Your Terminal ">41.9</A>is that it requires you to hardcode the escape sequences for aparticular terminal.If you use more than one kind of terminal, youhave to create separate aliases for each one.That's exactly thekind of problem that the <EMCLASS="emphasis">termcap</EM> and <EMCLASS="emphasis">terminfo</EM> databases were designed to solve.</P><TABLECLASS="para.programreference"BORDER="1"><TR><THVALIGN="TOP"><ACLASS="programreference"HREF="examples/index.htm"TITLE="tcap">tcap</A><BR></TH><TDVALIGN="TOP"><ACLASS="indexterm"NAME="AUTOID-46009"></A><ACLASS="indexterm"NAME="AUTOID-46011"></A><ACLASS="indexterm"NAME="AUTOID-46013"></A><ACLASS="indexterm"NAME="AUTOID-46015"></A>For each terminal in the database, there is a list of <SPANCLASS="link">terminal capabilities (<ACLASS="linkend"HREF="ch41_11.htm"TITLE="How termcap and terminfo Describe Terminals ">41.11</A>)</SPAN>.The <EMCLASS="emphasis">tput</EM> program (standard on any system with <EMCLASS="emphasis">terminfo</EM>)lets you print out the value of any individual capability.The <EMCLASS="emphasis">tcap</EM> program does the same for systems using <EMCLASS="emphasis">termcap</EM>.(<EMCLASS="emphasis">tcap</EM> was originally named <EMCLASS="emphasis">tc</EM>.We renamed it to avoid conflicts with <EMCLASS="emphasis">tc</EM>, the <EMCLASS="emphasis">ditroff</EM>interpreter program for Tektronix 4015 terminals.)This makes it possible to use terminalcapabilities such as those for standout mode in shell programs.</TD></TR></TABLE><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46028"></A>For example, a prompt issued by a shell program could behighlighted by the following code using <EMCLASS="emphasis">tput</EM>:</P><PCLASS="para"><TABLECLASS="screen.co"BORDER="1"><TR><THVALIGN="TOP"><PRECLASS="calloutlist">&#13;<ACLASS="co"HREF="ch08_06.htm"TITLE="8.6 Output Command-Line Arguments ">echo...\c</A> </PRE></TH><TDVALIGN="TOP"><PRECLASS="screen"># Store the terminfo capability to start standout mode into# the variable HIGHLIGHT; this might be bold, or inverse videoHIGHLIGHT=`tput smso` # Store the terminfo capability to end standout mode into# the variable NORMAL NORMAL=`tput rmso` # Echo a highlighted promptecho &quot;${HIGHLIGHT}Press Return to accept value: ${NORMAL}\c&quot;</PRE></TD></TR></TABLE></P><PCLASS="para">Capabilities that accept arguments (such as cursor movement sequences) will interpolate values that follow thecapability name on the command line.For example, to issuethe cursor motion sequence to move to the upper-left corner ofthe screen (row 0, column 0), you could type:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">$ <CODECLASS="userinput"><B>tput cup 0 0</B></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">Another case where <EMCLASS="emphasis">tput</EM> comes in useful is when commandsequences accidentally get sent to the screen, leaving output garbledor in a distracting highlight mode.It sometimes happens that a userreads a non-ASCII file, or reads a mail message with a control characteraccidentally imbedded, and ends up with gibberish.This is oftenbecause the sequence for entering an alternate character set has beensent to the terminal, and the screen is no longer readable to thehuman eye.The user can return to the normal character set two ways: by rebooting the terminal, or by entering <SPANCLASS="link"><EMCLASS="emphasis">tput init</EM> (<ACLASS="linkend"HREF="ch05_12.htm"TITLE="Initializing the Terminal with tput ">5.12</A>)</SPAN>on the command line.Using <EMCLASS="emphasis">tput</EM>, obviously, is much more efficient.</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">JS</SPAN>, <SPANCLASS="authorinitials">TOR</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch41_09.htm"TITLE="41.9 Commands to Adjust Your Terminal "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 41.9 Commands to Adjust Your Terminal "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch41_11.htm"TITLE="41.11 How termcap and terminfo Describe Terminals "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 41.11 How termcap and terminfo Describe Terminals "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">41.9 Commands to Adjust Your Terminal </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">41.11 How termcap and terminfo Describe Terminals </TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed &amp; awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -