This library supports NO_COLOR
. Setting this environment variable will
disable all text formatting when the texts are rendered.
(method) Text:new(str?: string|Text)
-> Text
Create a new Text
from a string.
Parameters:
str
— The text to be displayed in thisText
.
(method) Text:text(str: string)
-> Text
Set the text of this Text
.
Parameters:
str
— The text to be displayed in thisText
.
(method) Text:get_raw_text()
-> string
Retrieve the raw text contained within the Text
object.
(method) Text:fg(color: number|table)
-> Text
Set the foreground color of this Text
.
Parameters:
color
— The color to set. This can be either an ANSI256 color code, or a table of RGB values.
local text = require("luatext")
print(text.Text:new("Hello"):fg(160)) -- prints in red
print(text.Text:new("Hi"):fg({0, 255, 0})) -- prints in green
(method) Text:bg(color: number|table)
-> Text
Set the background color of this Text
.
Parameters:
color
— The color to set. This can be either an ANSI256 color code, or a table of RGB values.
local text = require("luatext")
print(text.Text:new("Hello"):bg(160)) -- prints on red background
print(text.Text:new("Hi"):bg({0, 255, 0})) -- prints on green background
(method) Text:bold()
-> Text
Make the fond bold.
(method) Text:dim()
-> Text
Make the text dim.
(method) Text:italic()
-> Text
Make the fond italic.
(method) Text:underlined()
-> Text
Make the text underlined.
(method) Text:blink()
-> Text
Make the text blink.
(method) Text:inverse()
-> Text
Invert the text.
Support for this may vary.
hidden
(method) Text:inverse()
-> Text
Hide the text
(method) Text:strikethrough()
-> Text
Make the text strikethrough.
(method) Text:framed()
-> Text
Frame the text.
Support for this may vary.
(method) Text:encircled()
-> Text
Encircle the text.
Support for this may vary.
(method) Text:overlined()
-> Text
Make the text overlined.
Support for this may vary.
(method) Text:append(...string|Text)
-> Text
Append one or more strings or Text
s to this string. Appended elements will inherit the
formatting of the original string. This is used to apply additional formatting or overwrite
formatting from the original string for a substring.
Parameters:
...
— The strings to append.
Print a red string, in which the word beautiful
is underlined:
local text = require("luatext")
local my_str = text
.Text
:new()
:fg(text.Color.Red)
:append(
"Hello ",
text.Text:new("beautiful"):underlined(),
" world"
)
print(my_str)
(method) Text:render()
-> string
Render the Text
, turning it into an escaped string. This typically does not need to be
called explicitly, as the Text
will automatically render when used in a string
context
(such as when printing it).
table
Standard ANSI colors. Can be used in place of any color code. Available values are:
Black
Red
Green
Yellow
Blue
Magenta
Cyan
White
BrightBlack
BrightRed
BrightGreen
BrightYellow
BrightBlue
BrightMagenta
BrightCyan
BrightWhite
string
The ANSI escape to reset all formatting. This is only to be used in bogus cases. A Text
will automatically reset the formatting at the very end of the string to avoid formatting leaking
into following text.