tput_examples

Package: WA2L/edrc 1.5.57
Section: Library Commands (3)
Updated: 22 February 2014
Index Return to Main Contents

 

NAME

tput_examples - examples on the use of the tput(1) command to control terminal outputs

 

SYNOPSIS

tput [ options ]

 

AVAILABILITY

WA2L/edrc

 

DESCRIPTION

This man page gives examples of tput(1) usages.

The tput(1) utility uses the terminfo database to make the values of terminal-dependent capabilities and information available to the shell, to initialize, reset the terminal, set colors, font weight and much more.

 

OPTIONS

-

 

ENVIRONMENT

-

 

EXIT STATUS

-

 

FILES

-

 

EXAMPLES

 

COLOUR COMMANDS

tput setab [1-7] # Set a background colour using ANSI escape
tput setaf [1-7] # Set a foreground colour using ANSI escape

Colors are as follows:

Num  Colour    #define         RGB

0    black     COLOR_BLACK     0,0,0
1    red       COLOR_RED       max,0,0
2    green     COLOR_GREEN     0,max,0
3    yellow    COLOR_YELLOW    max,max,0
4    blue      COLOR_BLUE      0,0,max
5    magenta   COLOR_MAGENTA   max,0,max
6    cyan      COLOR_CYAN      0,max,max
7    white     COLOR_WHITE     max,max,max

There are also non-ANSI versions of the colour setting functions (setb instead of setab, and setf instead of setaf) which use different numbers, not given here.

 

TEXT MODE COMMANDS

tput bold    # Select bold mode
tput dim     # Select dim (half-bright) mode
tput smul    # Enable underline mode
tput rmul    # Disable underline mode
tput rev     # Turn on reverse video mode
tput smso    # Enter standout (bold) mode
tput rmso    # Exit standout mode
tput sgr 0   # Reset all attributes

 

CURSOR MOVEMENT COMMANDS

tput cup Y X # Move cursor to screen position X,Y (top left is 0,0)
tput cuf N   # Move N characters forward (right)
tput cub N   # Move N characters back (left)
tput cuu N   # Move N lines up
tput ll      # Move to last line, first column (if no cup)
tput sc      # Save the cursor position
tput rc      # Restore the cursor position
tput lines   # Output the number of lines of the terminal
tput cols    # Output the number of columns of the terminal

 

CLEAR AND INSERT COMMANDS

tput ech N   # Erase N characters
tput clear   # Clear screen and move the cursor to 0,0
tput el 1    # Clear to beginning of line
tput el      # clear to end of line
tput ed      # clear to end of screen
tput ich N   # Insert N characters (moves rest of line forward!)
tput il N    # Insert N lines

 

OTHER COMMANDS

tput bel     # play a bell

With compiz wobbly windows, the bel command makes the terminal wobble for a second to draw the user's attention.

 

EXAMPLE USAGE

echo "$(tput setaf 1)Red text $(tput setab 7)and white background$(tput sgr 0)"

 

PERFORMING MULTIPLE OPERATIONS AT ONCE

tput accepts scripts containing one command per line, which are executed in order before tput exits.

Avoid temporary files by echoing a multi-line string and piping it:

echo -e "setf 7etb 1" | tput -S  # set fg white and bg red

 

SEE ALSO

edrcintro(1), stty(1), termcap(4), terminfo(5), textcolor(3), tput(1), tty(1), tty_columns(1), tty_variable(1)

 

NOTES

Parts of this manpage were extracted from the blog entry on 'How to change the output color of echo in Linux' on stackoverflow.com answered by Drew Noakes on January 7th 2014 and modified to fit to the WA2L/edrc package. See http://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux for more information.

 

BUGS

-

 

AUTHOR

the text for this man page has its roots in the blog entry written by Drew Noakes.

tput_examples has been written by Christian Walther. Send suggestions and bug reports to wa2l@users.sourceforge.net . 

 

COPYRIGHT

Copyright © 2014 Christian Walther

This is free software; see edrc/doc/COPYING for copying conditions. There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


 

Index

NAME
SYNOPSIS
AVAILABILITY
DESCRIPTION
OPTIONS
ENVIRONMENT
EXIT STATUS
FILES
EXAMPLES
COLOUR COMMANDS
TEXT MODE COMMANDS
CURSOR MOVEMENT COMMANDS
CLEAR AND INSERT COMMANDS
OTHER COMMANDS
EXAMPLE USAGE
PERFORMING MULTIPLE OPERATIONS AT ONCE
SEE ALSO
NOTES
BUGS
AUTHOR
COPYRIGHT

This document was created by man2html using the manual pages.
Time: 16:54:46 GMT, August 28, 2024