`tput` is a command-line utility in Linux systems that allows you to control terminal settings, such as changing colors or setting font attributes. It provides a range of options for customizing your output and enhancing the user experience.
In this guide, we'll explore the various features of `tput`, including color printing, font styles, cursor positioning, and more. Whether you're a developer looking to create visually
appealing command-line interfaces (CLI) or a system administrator seeking to improve terminal usability, this article will equip you with the knowledge necessary to harness the full potential of `tput`.
Color Printing with tput
To print colored output using `tput`, you need to specify color codes in the format recommended by the terminal being used. Most terminals support ANSI escape sequences, which allow for text formatting and changing colors among other things.
Color Codes
* Foreground colors: 30-37 (red through white), 90-97 (bright red through bright white)
* Background colors: 40-47 (red through white), 100-107 (bright red through bright white)
Example Code for Color Printing
tput setaf 1 # red
echo "Hello"
tput setab 4 # blue background
echo "World"
Resetting Colors with tput
To reset the colors after printing, use `tput sgr0` or `tput reset`. This command resets all attributes back to default (color, font style, etc.).
No comments:
Post a Comment