Shell advanced screen output

Source: Internet
Author: User
For screen programs written under Shell, there are many echo commands, and this command is also relatively fast. next we will introduce another method, but the speed is relatively slow. to achieve this, system Needs

For screen programs written under Shell, there are many echo commands, and this command is also relatively fast. next we will introduce another method, but the speed is relatively slow. to achieve this, A color monitor and tput command are required on the system.

I. use

Before using tput, you must use the tput command in the script or command line to initialize the terminal.

$ Tput init

Tput generates three different outputs: Numeric, numeric, and Boolean (true/false ).

/String output/

Below are most common strings:

Name description

Bel alarm

Blink flash mode

Bold

Civis hide cursor

Clear screen

Cnorm does not hide the cursor

Cup move cursor to screen position (x, y)

Clear el to end of line

Ell to the beginning of the line

Smso startup highlighted mode

Rmso stop highlight mode

Smul starts underline mode

Rmul end underline mode

SC saves the current cursor position

Rc restores the cursor to the last saved position

Sgr0 normal screen

Rev reverse view

/Digital output/

Below are most commonly used digital outputs.

Name description

Cols column count

Ittab to set the width

Lines

/Boolean output/

There are only two Boolean operators in tput.

Name description

Chts cursor invisible

Hs has status line

For example, tput clear clears the screen

II. cursor position

You can use tput to place the cursor anywhere on the screen. Format:

Cup r c

R indicates the number of rows on the screen from top to bottom, and c indicates the number of rows on the screen.

It is best to compile it into a function so that the values of rows and columns can be passed to it.

Example:Run the tput cup 2 3 Command to place the cursor in rows 2nd and columns 3rd.

3. use color in the menu

Using colors for domains makes the data input screen look more professional. the following colors are a n s I standard colors, not all colors are suitable for all systems, most common colors are listed below.

1. foreground view:

Digit color numeric color

3 0 black 3 4 blue

3 1 Red 3 5 Purple

3 2 Green 3 6 cyan

3 3 yellow (or brown) color 3 7 white (or gray) color

2. background color:

Digit color numeric color

4 0 Black 4 4 blue

4 1 Red 4 5 Blue

4 2 Green 4 6 Blue

4 3 yellow (or brown) color 4 7 white (or gray) color

Example:Dark green echo "33 [40; 32 m"

You can use the tput command to enhance the control of the application's appearance and script. color settings can increase the professionalism of the application. Note that the color should not be too strong; otherwise, the speed will be very slow.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.