<HTML ><HEAD ><TITLE >Colours and Cursor Movement With tput</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Bash Prompt HOWTO" HREF="index.html"><LINK REL="UP" TITLE="ANSI Escape Sequences: Colours and Cursor Movement" HREF="c327.html"><LINK REL="PREVIOUS" TITLE="Xterm Title Bars and Screen" HREF="x395.html"><LINK REL="NEXT" TITLE="Special Characters: Octal Escape Sequences" HREF="c583.html"></HEAD ><BODY CLASS="SECT1" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Bash Prompt HOWTO: </TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="x395.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Chapter 6. ANSI Escape Sequences: Colours and Cursor Movement</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="c583.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="SECT1" ><H1 CLASS="SECT1" ><A NAME="AEN405" ></A >6.5. Colours and Cursor Movement With <B CLASS="COMMAND" >tput</B ></H1 ><P >As with so many things in Unix, there is more than one way to achieve the same ends. A utility called <B CLASS="COMMAND" >tput</B > can also be used to move the cursor around the screen, get back information about the status of the terminal, or set colours. <B CLASS="COMMAND" >man tput</B > doesn't go into much detail about the available commands, but Emilio Lopes e-mailed me to point out that <B CLASS="COMMAND" >man terminfo</B > will give you a <EM >huge</EM > list of capabilities, many of which are device independent, and therefore better than the escape sequences previously mentioned. He suggested that I rewrite all the examples using <B CLASS="COMMAND" >tput</B > for this reason. He is correct that I should, but I've had some trouble controlling it and getting it to do everything I want it to. However, I did rewrite one prompt which you can see as an example: <A HREF="clockt.html" >Section 12.8</A >. </P ><P >Here is a list of tput capabilities that I have found useful:</P ><P ></P ><DIV CLASS="VARIABLELIST" ><P ><B ><B CLASS="COMMAND" >tput</B > Colour Capabilities</B ></P ><DL ><DT ><B CLASS="COMMAND" >tput setab [1-7]</B ></DT ><DD ><P >Set a background colour using ANSI escape</P ></DD ><DT ><B CLASS="COMMAND" >tput setb [1-7]</B ></DT ><DD ><P >Set a background colour</P ></DD ><DT ><B CLASS="COMMAND" >tput setaf [1-7]</B ></DT ><DD ><P >Set a foreground colour using ANSI escape</P ></DD ><DT ><B CLASS="COMMAND" >tput setf [1-7]</B ></DT ><DD ><P >Set a foreground colour</P ></DD ></DL ></DIV ><P ></P ><DIV CLASS="VARIABLELIST" ><P ><B ><B CLASS="COMMAND" >tput</B > Text Mode Capabilities</B ></P ><DL ><DT ><B CLASS="COMMAND" >tput bold</B ></DT ><DD ><P >Set bold mode</P ></DD ><DT ><B CLASS="COMMAND" >tput dim</B ></DT ><DD ><P >turn on half-bright mode</P ></DD ><DT ><B CLASS="COMMAND" >tput smul</B ></DT ><DD ><P >begin underline mode</P ></DD ><DT ><B CLASS="COMMAND" >tput rmul</B ></DT ><DD ><P >exit underline mode</P ></DD ><DT ><B CLASS="COMMAND" >tput rev</B ></DT ><DD ><P >Turn on reverse mode</P ></DD ><DT ><B CLASS="COMMAND" >tput smso</B ></DT ><DD ><P >Enter standout mode (bold on rxvt)</P ></DD ><DT ><B CLASS="COMMAND" >tput rmso</B ></DT ><DD ><P >Exit standout mode</P ></DD ><DT ><B CLASS="COMMAND" >tput sgr0</B ></DT ><DD ><P >Turn off all attributes (doesn't work quite as expected)</P ></DD ></DL ></DIV ><P ></P ><DIV CLASS="VARIABLELIST" ><P ><B ><B CLASS="COMMAND" >tput</B > Cursor Movement Capabilities</B ></P ><DL ><DT ><B CLASS="COMMAND" >tput cup Y X</B ></DT ><DD ><P >Move cursor to screen location X,Y (top left is 0,0)</P ></DD ><DT ><B CLASS="COMMAND" >tput sc</B ></DT ><DD ><P >Save the cursor position</P ></DD ><DT ><B CLASS="COMMAND" >tput rc</B ></DT ><DD ><P >Restore the cursor position</P ></DD ><DT ><B CLASS="COMMAND" >tput lines</B ></DT ><DD ><P >Output the number of lines of the terminal</P ></DD ><DT ><B CLASS="COMMAND" >tput cols</B ></DT ><DD ><P >Output the number of columns of the terminal</P ></DD ><DT ><B CLASS="COMMAND" >tput cub N</B ></DT ><DD ><P >Move N characters left</P ></DD ><DT ><B CLASS="COMMAND" >tput cuf N</B ></DT ><DD ><P >Move N characters right</P ></DD ><DT ><B CLASS="COMMAND" >tput cub1</B ></DT ><DD ><P >move left one space</P ></DD ><DT ><B CLASS="COMMAND" >tput cuf1</B ></DT ><DD ><P >non-destructive space (move right one space)</P ></DD ><DT ><B CLASS="COMMAND" >tput ll</B ></DT ><DD ><P >last line, first column (if no cup)</P ></DD ><DT ><B CLASS="COMMAND" >tput cuu1</B ></DT ><DD ><P >up one line</P ></DD ></DL ></DIV ><P ></P ><DIV CLASS="VARIABLELIST" ><P ><B ><B CLASS="COMMAND" >tput</B > Clear and Insert Capabilities</B ></P ><DL ><DT ><B CLASS="COMMAND" >tput ech N</B ></DT ><DD ><P >Erase N characters</P ></DD ><DT ><B CLASS="COMMAND" >tput clear</B ></DT ><DD ><P >clear screen and home cursor</P ></DD ><DT ><B CLASS="COMMAND" >tput el1</B ></DT ><DD ><P >Clear to beginning of line</P ></DD ><DT ><B CLASS="COMMAND" >tput el</B ></DT ><DD ><P >clear to end of line</P ></DD ><DT ><B CLASS="COMMAND" >tput ed</B ></DT ><DD ><P >clear to end of screen</P ></DD ><DT ><B CLASS="COMMAND" >tput ich N</B ></DT ><DD ><P >insert N characters (moves rest of line forward!)</P ></DD ><DT ><B CLASS="COMMAND" >tput il N</B ></DT ><DD ><P >insert N lines</P ></DD ></DL ></DIV ><P >This is by no means a complete list of what <B CLASS="COMMAND" >terminfo</B > and <B CLASS="COMMAND" >tput</B > allow, in fact it's only the beginning. <B CLASS="COMMAND" >man tput</B > and <B CLASS="COMMAND" >man terminfo</B > if you want to know more.</P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="x395.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="c583.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Xterm Title Bars and Screen</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="c327.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Special Characters: Octal Escape Sequences</TD ></TR ></TABLE ></DIV ></BODY ></HTML >