Monday 23 March 2020

tput in Linux

tput usage

$ man tput
$ info tput

$ tput longname #full name of the current terminal type
xterm terminal emulator (X Window System)

$ tput -T screen longname
VT 100/ANSI X3.64 virtual terminal

Foreground & background color commands

tput setab [1-7] # Set the background color using ANSI escape
tput setaf [1-7] # Set the foreground color using ANSI escape

Colors are as follows:

No   Color        #define                R G B

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

















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

Cursor movement commands

tput cup Y X # Move cursor to screen postion 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

Reset and play bell commands

tput sgr0    # Reset text format to the terminal's default
tput bel     # Play a bell

Error Messages

tput displays various error messages if problems occur. In addition, it exits with one of the following status values:

0 Normal status; the given capability is present.
1 The given Boolean or string capability is not present.
2 Usage error; tput was given invalid arguments.
3 The terminal type given is unknown, or the termcap database can not be read.
4 The given capability is unknown.


Ref:- stackoverflow.com gnu.org linuxcommand.org

No comments:

Post a Comment