📄 ch41_11.htm
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 41] 41.11 How termcap and terminfo Describe Terminals </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly & Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly & Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:52:08Z"><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_10.htm"TITLE="41.10 Using terminfo Capabilities in Shell Programs "><LINKREL="next"HREF="ch41_12.htm"TITLE="41.12 Finding Out What Characters Your Terminal's Special Keys Send"></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_10.htm"TITLE="41.10 Using terminfo Capabilities in Shell Programs "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 41.10 Using terminfo Capabilities in Shell Programs "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_12.htm"TITLE="41.12 Finding Out What Characters Your Terminal's Special Keys Send"><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 41.12 Finding Out What Characters Your Terminal's Special Keys Send"BORDER="0"></A></TD></TR></TABLE> <HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-7967">41.11 How termcap and terminfo Describe Terminals </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46050"></A><ACLASS="indexterm"NAME="AUTOID-46053"></A><ACLASS="indexterm"NAME="AUTOID-46056"></A>The<SPANCLASS="link"><EMCLASS="emphasis">termcap</EM> and <EMCLASS="emphasis">terminfo</EM> databases (<ACLASS="linkend"HREF="ch05_02.htm"TITLE="The Idea of a Terminal Database ">5.2</A>)</SPAN>describe thecapabilities of terminals using a rather obscure and compactlanguage.At this point, the ASCII terminal market has slowed downand standardized, so it is not as essential as it used to be to write new terminal entries.However, there are still times when it's useful to know how to read an entry.For example, you may want to use particular capabilities <SPANCLASS="link">in a shell program (<ACLASS="linkend"HREF="ch41_10.htm"TITLE="Using terminfo Capabilities in Shell Programs ">41.10</A>)</SPAN>or<SPANCLASS="link">in a function key map (<ACLASS="linkend"HREF="ch41_12.htm"TITLE="Finding Out What Characters Your Terminal's Special Keys Send">41.12</A>)</SPAN>.</P><PCLASS="para">We won't give you a detailed list of all of the possiblecapabilities - that you can get from the <EMCLASS="emphasis">termcap</EM> or<EMCLASS="emphasis">terminfo</EM> manual page on your system.However, we do want togive you an introduction to the language of <EMCLASS="emphasis">termcap</EM> and<EMCLASS="emphasis">terminfo</EM>.</P><PCLASS="para">Here's a simplifiedentry for the Wyse Technology Wyse-50 terminal.The capabilities described here are only a subset sufficient to introduce the basic syntax of the language: </P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen"># incomplete termcap entry for the Wyse WY-50 n9|wy50|WY50| Wyse Technology WY-50:\ :bs:am:co#80:li#24:\ :up=^K:cl=^Z:ho=^^:nd=^L:cm=\E=%+ %+ :</PRE></BLOCKQUOTE></P><PCLASS="para">And here is the corresponding <EMCLASS="emphasis">terminfo</EM> source file:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen"># incomplete terminfo entry for Wyse WY-50wy50|WY50|Wyse Technology WY-50, am, cols#80, lines#24, cuu1=^K, clear=^Z, home=^^, cuf1=^L, cup=\E=%p1%'\s'%+%c%p2%'\s'%+%c,</PRE></BLOCKQUOTE></P><PCLASS="para">The backslash (<CODECLASS="literal">\</CODE>) character is used to suppress the newline in <EMCLASS="emphasis">termcap</EM>.<EMCLASS="emphasis">termcap</EM> entries must be defined on asingle logical line, with colons (<CODECLASS="literal">:</CODE>) separating each field.<EMCLASS="emphasis">terminfo</EM> does not require the entry to be on a single line, sobackslashes are not necessary.In <EMCLASS="emphasis">terminfo</EM>, commas are used asthe field separator.</P><PCLASS="para">The language certainly is not verbose!However, if we work through it methodically, it might begin to make sense.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46085"></A><ACLASS="indexterm"NAME="AUTOID-46088"></A>There are three types of lines in a <EMCLASS="emphasis">termcap</EM> or <EMCLASS="emphasis">terminfo</EM> file: comment lines, lines that list alias names for the terminal, and lines that specify terminal capabilities. </P><ULCLASS="itemizedlist"><LICLASS="listitem"><PCLASS="para"><EMCLASS="emphasis">Comment lines:</EM>The first line in both the <EMCLASS="emphasis">termcap</EM> and <EMCLASS="emphasis">terminfo</EM> entriesshown above is a comment line.</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen"># incomplete termcap entry for the Wyse WY-50# incomplete terminfo entry for the Wyse WY-50</PRE></BLOCKQUOTE></P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46102"></A><ACLASS="indexterm"NAME="AUTOID-46105"></A><ACLASS="indexterm"NAME="AUTOID-46108"></A>All comment lines begin with a hash mark (<CODECLASS="literal">#</CODE>).Embedded comments are not allowed: a line is either a comment or part of an entry.In <EMCLASS="emphasis">termcap</EM> and <EMCLASS="emphasis">terminfo</EM>, the convention is thatcomments precede the terminal they describe. </P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46116"></A><ACLASS="indexterm"NAME="AUTOID-46118"></A><ACLASS="indexterm"NAME="AUTOID-46121"></A><EMCLASS="emphasis">Name lines:</EM> The second line is a list of alias names for the terminal,separated by the vertical bar character.</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">n9|wy50|WY50| Wyse Technology WY-50:\ <ICLASS="lineannotation">...termcap</I>wy50|WY50|Wyse Technology WY-50, <ICLASS="lineannotation">...terminfo</I></PRE></BLOCKQUOTE></P><PCLASS="para">Multiple aliases are provided as a convenience to the user.The environment variable<SPANCLASS="link">TERM (<ACLASS="linkend"HREF="ch05_10.htm"TITLE="Finding What Terminal Names You Can Use ">5.10</A>)</SPAN>can be set to any one of thealiases.By convention, the last alias is the full name of the terminal.</P><PCLASS="para">The alias list is the first field of the terminal description, with a colon (<EMCLASS="emphasis">termcap</EM>) or comma (<EMCLASS="emphasis">terminfo</EM>) marking the end of the alias list and the start of the capabilities list.You could begin listing the capabilities immediately after this field, but it makes reading much easier if all the aliases are on oneline and the capabilities start on the next.</P><PCLASS="para">When a <EMCLASS="emphasis">terminfo</EM> source file is compiled with <EMCLASS="emphasis">tic</EM>, thecompiled data is placed in a file corresponding to the first alias (inthis case, <EMCLASS="emphasis">/usr/lib/terminfo/w/wy50</EM>), and a link iscreated for all other aliases but the last.In this example,TERM could be set to either <EMCLASS="emphasis">wy50</EM> or <EMCLASS="emphasis">WY50</EM> to access the compiled terminal description.</P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46142"></A><EMCLASS="emphasis">Capability lines:</EM>The remaining lines are the list of the actual terminal capabilities.These lines are indented (using a tab or blank spaces) to distinguish them from the line of terminal aliases.Note that theindentation of continued capability lines is not just cosmeticbut is a required part of the syntax.</P><PCLASS="para">In <EMCLASS="emphasis">termcap</EM>, capabilities are identified by a two-character name; in<EMCLASS="emphasis">terminfo</EM>, the capability names may have anywhere between two andfive characters.The capability name is the first thing in eachcapability field and describes a feature of the terminal.</P></LI></UL><PCLASS="para">There are three types of capability:</P><ULCLASS="itemizedlist"><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46152"></A><BCLASS="emphasis.bold">Boolean capabilities</B> consist of a capability name with no arguments.For example, <EMCLASS="emphasis">am</EM> (both <EMCLASS="emphasis">termcap</EM> and <EMCLASS="emphasis">terminfo</EM>)specifies that the terminal performs automatic right margins, wrapping the cursor to the start of the next line whenthe cursor reaches the last position on the current line.If <EMCLASS="emphasis">am</EM> is not specified, programs will assume that your terminaldoes not have this feature.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46161"></A><ACLASS="indexterm"NAME="AUTOID-46163"></A><ACLASS="indexterm"NAME="AUTOID-46165"></A><ACLASS="indexterm"NAME="AUTOID-46167"></A><EMCLASS="emphasis">am</EM> is an example of a Booleanfeature that is advantageous, but Booleans are also used to specifynegative features of your terminal - for example, if your terminaldoes not perform newlines in the expected way, you might have what iscalled the "newline glitch," and the entry may need to specify <EMCLASS="emphasis">xn</EM> (<EMCLASS="emphasis">termcap</EM>) or <CODECLASS="userinput"><B>xenl</B></CODE> (<EMCLASS="emphasis">terminfo</EM>) to tell programs to adjust for the terminal's peculiarity.</P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46176"></A><BCLASS="emphasis.bold">Numeric capabilities</B> consist of a capability name, asharp sign, and a number.For example, <CODECLASS="literal">co#80</CODE> (<EMCLASS="emphasis">termcap</EM>) and <CODECLASS="literal">cols#80</CODE> (<EMCLASS="emphasis">terminfo</EM>)says that the terminal has 80 columns.All numeric values are non-negative.</P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46185"></A><ACLASS="indexterm"NAME="AUTOID-46187"></A><ACLASS="indexterm"NAME="AUTOID-46190"></A><BCLASS="emphasis.bold">String capabilities</B> tell how to issue a command to the terminal.The format of a string capability is the capability name, followed by anequal sign, followed by the command sequence.For example,<CODECLASS="literal">up=^K</CODE> (<EMCLASS="emphasis">termcap</EM>) or <CODECLASS="literal">cuu1=^K</CODE> (<EMCLASS="emphasis">terminfo</EM>)specifies that the sequence CTRL-k will move the cursor up one line. </P></LI></UL><PCLASS="para">Now the Wyse-50 example should make more sense.First <EMCLASS="emphasis">termcap</EM>:</P><H4CLASS="figure"><ACLASS="title"NAME="UPT-ART-7967-FIG-0">Figure 41.1: A Simplified termcap Entry</A></H4><IMGCLASS="graphic"SRC="figs/7967a.gif"ALT="Figure 41.1"><PCLASS="para">Now <EMCLASS="emphasis">terminfo</EM>:</P><H4CLASS="figure"><ACLASS="title"NAME="UPT-ART-7967-FIG-1">Figure 41.2: A Simplified terminfo Entry</A></H4><IMGCLASS="graphic"SRC="figs/7967b.gif"ALT="Figure 41.2"><PCLASS="para">The examples demonstrate all three kinds of capabilities: Boolean,numeric, and string.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-46210"></A>The first two capabilities in the <EMCLASS="emphasis">termcap</EM> entry, andthe first capability in the <EMCLASS="emphasis">terminfo</EM> entry, are Boolean.</P><DLCLASS="variablelist"><DTCLASS="term"><EMCLASS="emphasis">bs</EM></DT><DDCLASS="listitem"><PCLASS="para">is the <EMCLASS="emphasis">termcap</EM> backspace capability, which means that the terminal willbackspace when sent the CTRL-h (<CODECLASS="literal">^H</CODE>) character.There is no <EMCLASS="emphasis">terminfo</EM> capability directly equivalent to <EMCLASS="emphasis">bs</EM>, so itis considered obsolete by <EMCLASS="emphasis">terminfo</EM> and by BSD 4.3 <EMCLASS="emphasis">termcap</EM>.In place of the <EMCLASS="emphasis">bs</EM> capability, <EMCLASS="emphasis">terminfo</EM> would explicitlydefine CTRL-h as the string to send the cursor left <CODECLASS="userinput"><B>cul1=</B></CODE><CODECLASS="literal">^H</CODE>).</P></DD><DTCLASS="term"><EMCLASS="emphasis">am</EM></DT><DDCLASS="listitem"><PCLASS="para"> <EMCLASS="emphasis">am</EM><ACLASS="indexterm"NAME="AUTOID-46236"></A><ACLASS="indexterm"NAME="AUTOID-46238"></A>is the automargin capability, also known as wraparound. It means thatwhen a line reaches the right edge of the screen, the terminalautomatically continues on the next line.</P></DD></DL><PCLASS="para">The next two capabilities are numeric.</P><DLCLASS="variablelist"><DTCLASS="term"><EMCLASS="emphasis">co#80</EM></DT><DTCLASS="term"><EMCLASS="emphasis">cols#80</EM></DT><DDCLASS="listitem"><PCLASS="para">says that the terminal has 80 columns.</P></DD><DTCLASS="term"><EMCLASS="emphasis">li#24</EM></DT><DTCLASS="term"><EMCLASS="emphasis">lines#24</EM></DT><DDCLASS="listitem"><PCLASS="para"> says that the terminal has 24 lines. </P></DD></DL><PCLASS="para">You will find that 80 characters and 24 linesis the most common screen size but that there are exceptions.Eighty characters was originally chosen because it is the width of a punch card, and 24 lines was chosen to take advantage of cheap televisionscreen technology.</P><PCLASS="para">The remainder of the fields in the Wyse-50 entry contain string capabilities.The first four of these are fairly simple:</P><DLCLASS="variablelist"><DT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -