-
-
Notifications
You must be signed in to change notification settings - Fork 4
Home
Use
.ansor.ansiinstead.
The terminal text attributes tutorial is still useful if you looking for it.
Pure POSIX shell script that print out textart
.textart is a pure POSIX shell script that print out textart.
A textart file have to follows those rules and conditions:
- The file has to be a shell script (
sh) begin with#!bin/shand executable (bychmod +x <file>) - File has to exit at the end with
exit 0 - The file have to output with
printfand output everything at once
For printf:
- The escape charater has to be
\033and not\e - The texts color and styles have to be reset (with
\033[0m) at the end of each line - Inside
printfmustn't have redundant newline:Bad:
printf " First line Middle line Last line "
Good:
printf "First line Middle line Last line"
- Inside
printfmustn't have redundant padding space at the beginning of line:Bad:
printf " First line Middle line Last line"
Good:
printf "First line Middle line Last line"
#!bin/sh
# Start
printf "
"
exit 0Here is how to set colors and styles in pure POSIX shell:
β ";": separator
βββββββββ
β β
\033[<param>;<param>;<param>m
βββββββββ¬βββ ββββ¬βββ ββββ¬ββββ
β β βββββββββ΄ββββββββ ββ "m": SGR code to exit
β β ββ SGR parameters (you can have more than one parameter)
β ββ "[": Define a sequence (many charaters in a code)
ββ "\033": Control Sequence Introducer (CSI)NOTE: Control Sequence Introducer should be
\033.
From Wikipedia, the free encyclopedia:
SGR (Select Graphic Rendition) sets display attributes. Several attributes can be set in the same sequence, separated by semicolons. Each display attribute remains in effect until a following occurrence of SGR resets it
Set text colors:
| Code | Value | Description |
|---|---|---|
38;5;<NUM> |
0-255 |
Set text foreground color to 256 color |
48;5;<NUM> |
0-255 |
Set text background color to 256 color |
38;2;<R>;<G>;<B> |
R, G, B
|
Set text foreground color to RGB color |
48;2;<R>;<G>;<B> |
R, G, B
|
Set text background color to RGB color |
4bit color (unrecommend)
Just use
\033[m38;5;(0-15) and\033[m48;5;(0-15) instead.
Set text foreground color to 4bit color:
| Normal | Bright | |
|---|---|---|
| Black | 30 |
90 |
| Red | 31 |
91 |
| Green | 32 |
92 |
| Yellow | 33 |
93 |
| Blue | 34 |
94 |
| Magenta | 35 |
95 |
| Cyan | 36 |
96 |
| White | 37 |
97 |
Set text background color to 4bit color:
| Normal | Bright | |
|---|---|---|
| Black | 40 |
100 |
| Red | 41 |
101 |
| Green | 42 |
102 |
| Yellow | 43 |
103 |
| Blue | 44 |
104 |
| Magenta | 45 |
105 |
| Cyan | 46 |
106 |
| White | 47 |
107 |
Set text styles:
| Code | Description |
|---|---|
0 |
Reset text formatting and colors (the whole sequence can be written as \033[m) |
1 |
Bold text |
2 |
Faint text |
3 |
Italic text |
4 |
Underline text |
5 |
Slow blink |
6 |
Fast blink (not widely supported) |
7 |
Swap foreground and background colors |
8 |
Hidden text |
9 |
Strike-through text |
Learn more SGR parameters here.
Special thanks to:
Copyright Β© 2020 by NNB
This work is licensed under a Creative Commons Attribution 4.0 International License.
