Skip to content

Latest commit

 

History

History
375 lines (253 loc) · 5.03 KB

reference.md

File metadata and controls

375 lines (253 loc) · 5.03 KB

LuaText


This library supports NO_COLOR. Setting this environment variable will disable all text formatting when the texts are rendered.

Text

new

(method) Text:new(str?: string|Text)
  -> Text

Create a new Text from a string.

Parameters:

  • str — The text to be displayed in this Text.

Back to top


text

(method) Text:text(str: string)
  -> Text

Set the text of this Text.

Parameters:

  • str — The text to be displayed in this Text.

Back to top


get_raw_text

(method) Text:get_raw_text()
  -> string

Retrieve the raw text contained within the Text object.

Back to top


fg

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

fg example

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

Back to top


bg

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

bg Example

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

Back to top


bold

(method) Text:bold()
  -> Text

Make the fond bold.

Back to top


dim

(method) Text:dim()
  -> Text

Make the text dim.

Back to top


italic

(method) Text:italic()
  -> Text

Make the fond italic.

Back to top


underlined

(method) Text:underlined()
  -> Text

Make the text underlined.

Back to top


blink

(method) Text:blink()
  -> Text

Make the text blink.

Back to top


inverse

(method) Text:inverse()
  -> Text

Invert the text.

Support for this may vary.

Back to top


hidden

(method) Text:inverse()
  -> Text

Hide the text

Back to top


strikethrough

(method) Text:strikethrough()
  -> Text

Make the text strikethrough.

Back to top


framed

(method) Text:framed()
  -> Text

Frame the text.

Support for this may vary.

Back to top


encircled

(method) Text:encircled()
  -> Text

Encircle the text.

Support for this may vary.

Back to top


overlined

(method) Text:overlined()
  -> Text

Make the text overlined.

Support for this may vary.

Back to top


append

(method) Text:append(...string|Text)
  -> Text

Append one or more strings or Texts 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.

append example

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)

Back to top


render

(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).

Back to top


Color

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

Back to top


RESET

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.

Back to top