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

📄 ch41_09.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 41] 41.9 Commands to Adjust Your Terminal </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:04Z"><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_08.htm"TITLE="41.8 ptys and Window Systems "><LINKREL="next"HREF="ch41_10.htm"TITLE="41.10 Using terminfo Capabilities in Shell Programs "></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_08.htm"TITLE="41.8 ptys and Window Systems "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 41.8 ptys and Window Systems "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_10.htm"TITLE="41.10 Using terminfo Capabilities in Shell Programs "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 41.10 Using terminfo Capabilities in Shell Programs "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-0426">41.9 Commands to Adjust Your Terminal </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-45935"></A><ACLASS="indexterm"NAME="AUTOID-45938"></A><ACLASS="indexterm"NAME="AUTOID-45941"></A>Most terminals and window systems read every character that the hostcomputer sends to them.They're watching for an <EMCLASS="emphasis">escape sequence</EM>, a series of charactersthat give commands to the terminal or window.(From now on, I'll just say &quot;terminal.&quot;But this article applies to windows, too.)When the terminal sees an escape sequence, it performs the commandinstead of showing you the characters.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-45945"></A>You can send these escape sequences yourself, from your UNIX account.For instance, maybe some program has accidentally left your terminal set toreverse video.If you're using an ANSI terminal (like a VT100) you couldtype an<SPANCLASS="link"><EMCLASS="emphasis">echo</EM> command (<ACLASS="linkend"HREF="ch08_06.htm"TITLE="Output Command-Line Arguments ">8.6</A>)</SPAN>to send the sequence<CODECLASS="literal">^[[0m</CODE> (where <CODECLASS="literal">^[</CODE> is an ESCape character) toturn off reverse video.However, it's usually easier to make aliases,a shell function or script that doesthe same thing.</P><PCLASS="para">These escape sequences should be documented in your terminal's manual.In this article, I'll use sequences for a VT102 or compatible terminal.If you're trying to make your setup more general so that it works on lots ofterminals, you should use a command like<SPANCLASS="link"><EMCLASS="emphasis">tput</EM> or <EMCLASS="emphasis">tcap</EM> (<ACLASS="linkend"HREF="ch41_10.htm"TITLE="Using terminfo Capabilities in Shell Programs ">41.10</A>)</SPAN>that reads your terminal's <EMCLASS="emphasis">terminfo</EM> or <EMCLASS="emphasis">termcap</EM> information.</P><PCLASS="para">For example, you might decide that it's easier to read a complicateddisplay when it's in reverse video.To put it in reverse video and go back to normal video later:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>Revvid</B></CODE>%   <ICLASS="lineannotation">...type commands; all text shows in reverse video...</I>% <CODECLASS="userinput"><B>Normal</B></CODE>%   <ICLASS="lineannotation">...now everything is in normal video...</I></PRE></BLOCKQUOTE></P><PCLASS="para">Most full-screen programs (<EMCLASS="emphasis">vi</EM>, etc.) re-initialize your terminal.That can undo some of what these commands do.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-45968"></A>To write the script, make a file named for one of the aliases, like<EMCLASS="emphasis">Clear</EM>.The first line of the script stores an ESC character in a<SPANCLASS="link">shell variable (<ACLASS="linkend"HREF="ch06_08.htm"TITLE="Shell Variables ">6.8</A>)</SPAN>named <EMCLASS="emphasis">e</EM>.It's used in all the other aliases as <CODECLASS="literal">${e}</CODE>:</P><PCLASS="para"><TABLECLASS="screen.co"BORDER="1"><TR><THVALIGN="TOP"><PRECLASS="calloutlist">&#13;<ACLASS="co"HREF="ch45_35.htm"TITLE="45.35 Using a Control Character in a Script ">echo..3'</A> <ACLASS="co"HREF="ch44_15.htm"TITLE="44.15 Handling Command-Line Arguments in Shell Scripts ">$*</A> &#13;</PRE></TH><TDVALIGN="TOP"><PRECLASS="screen">&#13;#! /bin/sh# SENDS VT102 AND COMPATIBLE TERMINAL CONTROL ESCAPE SEQUENCESe=&quot;`echo e | tr e '\033'`&quot;  # Make an ESCape character portablycase &quot;$0&quot; in*Clear) seq=&quot;${e}[;H${e}[2J&quot;  ;;# move to top left, clear screen# ALTERNATE CHARACTER SETS.  YOU USUALLY WANT &quot;NOG&quot; TO CLEAR THESE# WHEN YOUR TERMINAL GETS IN THIS MODE ACCIDENTALLY:*NOG) seq=&quot;${e}(B&quot; ;;       # cancel graphics*Graphics) seq=&quot;${e}(0&quot; ;;  # lower-case letters become graphics# NOTE: THESE WON'T WORK FOR FULL-SCREEN APPLICATIONS LIKE vi.# BETTER TO RESET YOUR TERMINAL PARAMETERS (tset, stty):*C132) seq=&quot;${e}[?3;h&quot; ;;   # 132-column mode*C80) seq=&quot;${e}[?3;l&quot; ;;    # 80-column mode*Revvid) seq=&quot;${e}[?5;h&quot; ;; # Reverse video*Normal) seq=&quot;${e}[?5;l&quot; ;; # Normal video# WRITE MESSAGE TO TERMINAL STATUS LINE (NICE FOR REMINDERS)#       EXAMPLE: ToStatus Clean out your files!# AND CLEAR IT.*ToStatus) seq=&quot;${e}7${e}[25;1f${e}[0K$*${e}8&quot; ;;*ClrStatus) seq=&quot;${e}7${e}[25;1f${e}[0K${e}8&quot; ;;*) echo &quot;$0: HELP - can't run myself.&quot; 1&gt;&amp;2; exit 1;;esac# SEND $seq TO TERMINAL WITHOUT INTERPRETATION BY SYSTEM V echo:cat &lt;&lt; END_OF_seq$seqEND_OF_seqexit 0</PRE></TD></TR></TABLE></P><PCLASS="para">You can install this script from the CD-ROMor from the<SPANCLASS="link">online archive (<ACLASS="linkend"HREF="ch52_07.htm"TITLE="Other Ways to Get the Software ">52.7</A>)</SPAN>.If you don't get the file from the disc,be careful to type those escape sequences exactly.The <EMCLASS="emphasis">Graphics</EM> command uses the digit 0, not the letter O.The <EMCLASS="emphasis">ToStatus</EM> and<EMCLASS="emphasis">ClrStatus</EM> commands use the digit 1 (one), not the letter l (L).If you get the script from the archive,ask <EMCLASS="emphasis">tar</EM> to install <EMCLASS="emphasis">Clear</EM> and its eight other links:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>tar xvf </B></CODE><CODECLASS="replaceable"><I>archive.tar</I></CODE><CODECLASS="userinput"><B> Clear NOG Graphics C132 \C80 Revvid Normal ToStatus ClrStatus</B></CODE>x Clear, 1371 bytes, 3 tape blocksNOG linked to ClearGraphics linked to Clear   ...</PRE></BLOCKQUOTE></P><PCLASS="para">&#13;The script<SPANCLASS="link">tests the name it was called with (<ACLASS="linkend"HREF="ch44_22.htm"TITLE="Finding a Program Name; Multiple Program Names ">44.22</A>)</SPAN>,in <CODECLASS="literal">$0</CODE>, to decidewhich string to output (the asterisk (<CODECLASS="literal">*</CODE>) matches any pathnamebefore the command name).This trick saves disk space.You can add other commands, too, by adding a line to the <CODECLASS="literal">case</CODE>and another link.</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">JP</SPAN> <SPANCLASS="bibliomisc">based on a suggestion and aliases by Bruce Barnett</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_08.htm"TITLE="41.8 ptys and Window Systems "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 41.8 ptys and Window Systems "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_10.htm"TITLE="41.10 Using terminfo Capabilities in Shell Programs "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 41.10 Using terminfo Capabilities in Shell Programs "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">41.8 ptys and Window Systems </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.10 Using terminfo Capabilities in Shell Programs </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 + -