Skip to content
This repository has been archived by the owner on Aug 28, 2021. It is now read-only.
NNB edited this page Jul 30, 2021 · 10 revisions

Do not use this format!

Use .ans or .ansi instead.

The terminal text attributes tutorial is still useful if you looking for it.

.textart

Pure POSIX shell script that print out textart

About

.textart is a pure POSIX shell script that print out textart.

Contents

Conditions

A textart file have to follows those rules and conditions:

  • The file has to be a shell script (sh) begin with #!bin/sh and executable (by chmod +x <file>)
  • File has to exit at the end with exit 0
  • The file have to output with printf and output everything at once

For printf:

  • The escape charater has to be \033 and not \e
  • The texts color and styles have to be reset (with \033[0m) at the end of each line
  • Inside printf mustn't have redundant newline:

    Bad:

    printf "
    First line
    Middle line
    Last line
    "

    Good:

    printf "First line
    Middle line
    Last line"
  • Inside printf mustn'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"

Template

#!bin/sh


# Start
printf "
"

exit 0

Terminal text attributes

Here 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.

SGR parameters

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.

Credits

Special thanks to: