Shell script to achieve a color progress bar

1. Progress bar:

The progress bar to be implemented today has the following parts that need to be paid attention to:

 ①The first is a progress bar display that increases with time, a percentage display and a loading rotation icon;

 ②The focus of today is to color the progress bar to make it more beautiful. The specific method is:

       The character color of the terminal is controlled by the escape character sequence, which is a system display function in text mode and has nothing to do with the specific language.

       The escape character sequence begins with the control character'ESC'. The ASCII code of this character is 27 in decimal, 0x1B in hexadecimal, and 033 in octal. Most escape sequences exceed two characters, so they usually start with'ESC' and'['. This initial sequence is called the control sequence leader and is usually replaced by'\033[' or'\e['. When setting terminal display attributes through escape sequences, the following forms can be used:

       \ 0333 [Param {; Param; ...} m 或 \ and [Param {; Param; ...} m 

       Among them, '033[' or'\e[' leads the escape sequence,'m' means to set the attribute and end the escape sequence, and Param is the attribute value.

       Display: 0 (default), 1 (bold/highlight), 22 (non-bold), 4 (single underline), 24 (no underline), 5 (flicker), 25 (no flicker), 7 (reverse display) / Flip the foreground and background colors), 27 (no reverse display).

       Color: 0 (black), 1 (red), 2 (green), 3 (yellow), 4 (blue), 5 (magenta), 6 (cyan), 7 (white).

       Foreground color is 30+color; background color is 40+color value.

 

2. Realization:

        

 

3. Results:

        

 

 

Guess you like

Origin blog.csdn.net/wxt_hillwill/article/details/74909784