Module terminal.text
Terminal text module.
Provides utilities to set text attributes in terminals.
Functions
attr (attr) | Sets all text attributes/colors and writes it to the terminal. |
blink ([on=true]) | (Un)sets the blink attribute and writes it to the terminal. |
brightness (brightness) | Sets the brightness and writes it to the terminal. |
reverse ([on=true]) | (Un)sets the reverse attribute and writes it to the terminal. |
underline ([on=true]) | (Un)sets the underline attribute and writes it to the terminal. |
Sequences
attr_seq (attr) | Creates an ansi sequence to set all text attributes/colors without writing it to the terminal. |
blink_seq ([on=true]) | Creates an ansi sequence to (un)set the blink attribute without writing it to the terminal. |
brightness_seq (brightness) | Creates an ansi sequence to set the brightness without writing it to the terminal. |
reverse_seq ([on=true]) | Creates an ansi sequence to (un)set the reverse attribute without writing it to the terminal. |
underline_seq ([on=true]) | Creates an ansi sequence to (un)set the underline attribute without writing it to the terminal. |
Functions
- attr (attr)
-
Sets all text attributes/colors and writes it to the terminal.
Every element omitted in the attr table will be taken from the current top of the stack.
Parameters:
- attr
table
the attributes to set, see
attrs
for details.
Returns:
-
true
Usage:
terminal.text.attr({ fg = "red", bg = "black", brightness = 3, underline = true, blink = false, reverse = false })
- attr
table
the attributes to set, see
- blink ([on=true])
-
(Un)sets the blink attribute and writes it to the terminal.
Parameters:
- on boolean whether to set blink (default true)
Returns:
-
true
- brightness (brightness)
-
Sets the brightness and writes it to the terminal.
Parameters:
- brightness string or integer the brightness to set
Returns:
-
true
- reverse ([on=true])
-
(Un)sets the reverse attribute and writes it to the terminal.
Parameters:
- on boolean whether to set reverse (default true)
Returns:
-
true
- underline ([on=true])
-
(Un)sets the underline attribute and writes it to the terminal.
Parameters:
- on boolean whether to set underline (default true)
Returns:
-
true
Sequences
- attr_seq (attr)
-
Creates an ansi sequence to set all text attributes/colors without writing it to the terminal.
Only set what you change. Every element omitted in the attr table will be taken from the current top of the stack.
Parameters:
- attr the attributes to set, with keys:
- fg
string or integer
the foreground color to set. Base color (string), or extended color (number). Takes precedence of
fg_r
,fg_g
,fg_b
. (optional) - fg_r integer the red value of the foreground color to set. (optional)
- fg_g integer the green value of the foreground color to set. (optional)
- fg_b integer the blue value of the foreground color to set. (optional)
- bg
string or integer
the background color to set. Base color (string), or extended color (number). Takes precedence of
bg_r
,bg_g
,bg_b
. (optional) - bg_r integer the red value of the background color to set. (optional)
- bg_g integer the green value of the background color to set. (optional)
- bg_b integer the blue value of the background color to set. (optional)
- brightness string or number the brightness level to set (optional)
- underline boolean whether to set underline (optional)
- blink boolean whether to set blink (optional)
- reverse boolean whether to set reverse (optional)
- fg
string or integer
the foreground color to set. Base color (string), or extended color (number). Takes precedence of
Returns:
-
string
ansi sequence to write to the terminal
Usage:
local str = terminal.text.attrs({ fg = "red", bg = "black", brightness = 3, underline = true, blink = false, reverse = false })
- attr the attributes to set, with keys:
- blink_seq ([on=true])
-
Creates an ansi sequence to (un)set the blink attribute without writing it to the terminal.
Parameters:
- on boolean whether to set blink (default true)
Returns:
-
string
ansi sequence to write to the terminal
- brightness_seq (brightness)
-
Creates an ansi sequence to set the brightness without writing it to the terminal. brightness can be one of the following:
0
,"off"
, or"invisble"
for invisible1
,"low"
, or"dim"
for dim2
,"normal"
for normal3
,"high"
,"bright"
, or"bold"
for bright
Parameters:
- brightness string or integer the brightness to set
Returns:
-
string
ansi sequence to write to the terminal
- reverse_seq ([on=true])
-
Creates an ansi sequence to (un)set the reverse attribute without writing it to the terminal.
Parameters:
- on boolean whether to set reverse (default true)
Returns:
-
string
ansi sequence to write to the terminal
- underline_seq ([on=true])
-
Creates an ansi sequence to (un)set the underline attribute without writing it to the terminal.
Parameters:
- on boolean whether to set underline (default true)
Returns:
-
string
ansi sequence to write to the terminal