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

📄 ch05_08.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 5] 5.8 Terminal Escape Sequences </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:33: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="ch05_01.htm"TITLE="5. Setting Up Your Terminal"><LINKREL="prev"HREF="ch05_07.htm"TITLE="5.7 What termcap and terminfo Do and Don't Control "><LINKREL="next"HREF="ch05_09.htm"TITLE="5.9 Setting Your Erase, Kill, and Interrupt Characters "></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="ch05_07.htm"TITLE="5.7 What termcap and terminfo Do and Don't Control "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 5.7 What termcap and terminfo Do and Don't Control "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 5<BR>Setting Up Your Terminal</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch05_09.htm"TITLE="5.9 Setting Your Erase, Kill, and Interrupt Characters "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 5.9 Setting Your Erase, Kill, and Interrupt Characters "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-7927">5.8 Terminal Escape Sequences </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-5303"></A><ACLASS="indexterm"NAME="AUTOID-5305"></A>Most terminals use special character strings called <EMCLASS="emphasis">escapesequences</EM> to control their operation.These strings begin with theescape character <SPANCLASS="link">(ASCII character 033) (<ACLASS="linkend"HREF="ch51_03.htm"TITLE="ASCII Characters: Listing and Getting Values ">51.3</A>)</SPAN>.</P><PCLASS="para">This character can be generated alone by the ESC key found on mostkeyboards, or by typing the left bracket character while holding downthe CONTROL key (often shown as <CODECLASS="literal">^[</CODE>).<ACLASS="indexterm"NAME="AUTOID-5312"></A><ACLASS="indexterm"NAME="AUTOID-5314"></A>But it's also generated by manyof the special keys on your keyboard.For example, an UP&nbsp;ARROW keymight generate an escape sequence like <CODECLASS="literal">^[OA</CODE>.When the terminal seesthis sequence of characters, it knows to move the cursor up one line.</P><PCLASS="para">The special escape sequences used by your terminal arestored in the terminal's <SPANCLASS="link">termcap or terminfo entry (<ACLASS="linkend"HREF="ch41_11.htm"TITLE="How termcap and terminfo Describe Terminals ">41.11</A>, <ACLASS="linkend"HREF="ch05_02.htm"TITLE="The Idea of a Terminal Database ">5.2</A>)</SPAN>,which allows programs to respond appropriately to all of the specialkeys on the keyboard.Programs themselves issue escape sequences to dosuch things as move around the screen, highlight text, and so on.</P><PCLASS="para">However, there are cases where it's useful to issue escape sequencesmanually&nbsp;- or in an alias or shell script that you write.Forexample, you can <SPANCLASS="link">highlight your prompt (<ACLASS="linkend"HREF="ch07_08.htm"TITLE="Highlighting in Shell Prompts ">7.8</A>)</SPAN>or <SPANCLASS="link">write an alias to switch your terminal display to inverse video (<ACLASS="linkend"HREF="ch41_09.htm"TITLE="Commands to Adjust Your Terminal ">41.9</A>)</SPAN>.</P><PCLASS="para">Most of our examples use escape sequences for the common DEC VT100 series of terminals (which are also recognized by almost all terminal emulation programs).</P><PCLASS="para">How do you find out what escape sequences your terminal uses?Afterall, it is quite hardware-specific.If you have a terminal manual,they should be listed there.Otherwise, you can <SPANCLASS="link">look at the termcap or terminfo listing itself (<ACLASS="linkend"HREF="ch05_10.htm"TITLE="Finding What Terminal Names You Can Use ">5.10</A>)</SPAN>,and with the help of the manual page, or abook such as O'Reilly &amp; Associates' <EMCLASS="emphasis">termcap &amp; terminfo</EM>,decipher the obscure language used there.Or, use a program like<SPANCLASS="link"><EMCLASS="emphasis">tcap</EM> or <EMCLASS="emphasis">tput</EM> (<ACLASS="linkend"HREF="ch41_10.htm"TITLE="Using terminfo Capabilities in Shell Programs ">41.10</A>)</SPAN>;it will find those sequences for you.</P><PCLASS="para">To actually type an escape sequence into a file, use your editor's &quot;quote next character command&quot;(<SPANCLASS="link">CTRL-v in <EMCLASS="emphasis">vi</EM> (<ACLASS="linkend"HREF="ch31_06.htm"TITLE="Protecting Keys from Interpretation by ex ">31.6</A>)</SPAN>)before pressing the ESC key.To use an escape character inan alias, try the technique shown in article<ACLASS="xref"HREF="ch41_09.htm"TITLE="Commands to Adjust Your Terminal ">41.9</A>.</P><PCLASS="para">Don't be confused if you see an escape sequence that looks like this:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">^[[1m</PRE></BLOCKQUOTE></P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-5339"></A>Some terminals use a real left bracket at the start of their escapesequence; it will follow the escape character itself (represented as<CODECLASS="literal">^[</CODE>).Even though they look the same on the screen, they are reallydifferent characters (CTRL-<CODECLASS="literal">[</CODE> or ESC is different from<CODECLASS="literal">[</CODE>, just likeCTRL-c is different from <CODECLASS="literal">C</CODE>).</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <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="ch05_07.htm"TITLE="5.7 What termcap and terminfo Do and Don't Control "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 5.7 What termcap and terminfo Do and Don't Control "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="ch05_09.htm"TITLE="5.9 Setting Your Erase, Kill, and Interrupt Characters "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 5.9 Setting Your Erase, Kill, and Interrupt Characters "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">5.7 What termcap and terminfo Do and Don't Control </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">5.9 Setting Your Erase, Kill, and Interrupt Characters </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 + -