Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use tput Command in Linux

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "Linux tput command use method", in daily operation, I believe many people in Linux tput command use method problems have doubts, Xiaobian consulted all kinds of information, sorted out simple and easy to use operation method, hope to answer "Linux tput command use method" doubts helpful! Next, please follow the small series to learn together!

The tput command initializes and manipulates your terminal session through the terminfo database. By using tput, you can change several terminal functions, such as moving or changing the cursor, changing text properties, and clearing specific areas of the terminal screen. Like most commands in UNIX, the tput command can be used either on the shell command line or in shell scripts. To give you a better understanding of tput, this article starts at the command line and then follows with shell script examples. The tput command initializes and manipulates your terminal session through the terminfo database. By using tput you can change several terminal functions, such as moving or changing the cursor, changing text properties, and clearing specific areas of the terminal screen. Let's first look at its common parameters:

parameters

(1)String Output Parameter Settings

bel alarm

blink mode

bold bold

civis hide cursor

clear clear screen

cnorm does not hide cursors

cup Move cursor to screen position (x, y)

el clear to end of line

ell clear to the beginning of the line

smso enable highlight mode

RMSO Stop Protruding Mode

smul start underline mode

rmul end underscore mode

sc Save current cursor position

rc restore cursor to last save position

sgr0 Normal screen

rev reverse view

(2)Digital Output Parameter Settings

COLs Number of columns

ittab set width

lines lines

(3)Boolean Output Parameter Settings

chts cursor invisible

hs has status lines

application

Cursor Properties

Moving the cursor or changing cursor properties can be useful in UNIX shell scripts or on the command line. In some cases, you may need to enter sensitive information, such as a password, or enter information in two different areas on the screen. In such cases, using tput may be helpful.

move the cursor

Using tput makes it easy to move the cursor position across devices. By using the cup option in tput, or cursor position, you can move the cursor to any X or Y coordinate in the rows and columns of the device. The coordinates of the upper-left corner of the device are (0,0).

To move the cursor to row 1 (Y) of column 5 (X) on a device, simply execute tput cup 5 1. Another example is tput cup 23 45, which moves the cursor to line 45 on column 23.

Move the cursor and display information

Another useful cursor positioning technique is to move the cursor, execute a command to display information, and then return to the previous cursor position:

The code is as follows:

(tput sc ; tput cup 23 45 ; echo "Input from tput/echo at 23/45" ; tput rc)

Let's analyze the subshell command:

The code is as follows:

tput sc

You must first save the current cursor position. To save the current cursor position, include the sc option or "save cursor position."

The code is as follows:

tput cup 23 45

After saving the cursor position, the cursor coordinates move to (23,45).

The code is as follows:

echo "Input from tput/echo at 23/45"

Display information into stdout.

The code is as follows:

tput rc

After displaying this information, the cursor must return to the original position saved using tput sc. To return the cursor to its last saved position, include the rc option or "restore cursor position."

Note: since this article first details executing tput from the command line, you might find it simpler to execute commands in your own subshell than to execute each command individually and then display a prompt before each command is executed.

Change the properties of the cursor

There are times when you don't want to see a cursor when displaying data to a device. Turning the cursor invisible can make the screen look cleaner when data scrolls. To make the cursor invisible, use the civic option (for example, tput civic). After the data is fully displayed, you can use the cnorm option to turn the cursor visible again.

text properties

Changing the way text is displayed can draw attention to a group of words in a menu or alert users to something important. You can change text properties by bolding text, underlining text, changing background and foreground colors, and reversing color schemes.

To change the color of text, use the setb option (for setting the background color) and the setf option (for setting the foreground color) and the color values assigned in the terminfo database. In general, assigned values correspond to colors as follows, but this may vary from UNIX system to UNIX system:

0: Black

1: Blue

2: Green

3: Cyan

4: Red

5: Magenta

6: Yellow

7: White

Execute the following example command to change the background color to yellow and the foreground color to red:

The code is as follows:

tput setb 6

tput setf 4

To reverse the current color scheme, simply execute tput rev.

Sometimes coloring the text isn't enough, meaning you want to get the user's attention in another way. This can be done in two ways: by making the text bold or by underlining it.

To change text to bold, use the bold option. To start underlining, use the smul option. After finishing displaying underlined text, use the rmul option.

At this point, on the "Linux tput command in the use of the method" of learning is over, I hope to solve everyone's doubts. Theory and practice can better match to help you learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report