class

Crayon::Text

Inherits Reference < Object

Constants

ANSI_END = "\e[0;m"

ANSI escape codes for the end of the string

ANSI_START = "\e[%s%s%sm"

ANSI escape codes for the start of the string

Instance methods

black(str : String | Char | Nil = nil) : self | String

Alias of #set_color(Color::Black, str)

Source
blackbg(str : String | Char | Nil = nil) : self | String

Alias of #set_bg_color(Color::Black, str)

Source
blue(str : String | Char | Nil = nil) : self | String

Alias of #set_color(Color::Blue, str)

Source
bluebg(str : String | Char | Nil = nil) : self | String

Alias of #set_bg_color(Color::Blue, str)

Source
bold(str : String | Char | Nil = nil) : self | String

Alias of #set_style(Style::Bold, str)

Source
cyan(str : String | Char | Nil = nil) : self | String

Alias of #set_color(Color::Cyan, str)

Source
cyanbg(str : String | Char | Nil = nil) : self | String

Alias of #set_bg_color(Color::Cyan, str)

Source
encode(str : String | Char) : String

Add ANSI escape codes to a string

Source
green(str : String | Char | Nil = nil) : self | String

Alias of #set_color(Color::Green, str)

Source
greenbg(str : String | Char | Nil = nil) : self | String

Alias of #set_bg_color(Color::Green, str)

Source
inverse(str : String | Char | Nil = nil) : self | String

Alias of #set_style(Style::Inverse, str)

Source
italic(str : String | Char | Nil = nil) : self | String

Alias of #set_style(Style::Italic, str)

Source
magenta(str : String | Char | Nil = nil) : self | String

Alias of #set_color(Color::Magenta, str)

Source
magentabg(str : String | Char | Nil = nil) : self | String

Alias of #set_bg_color(Color::Magenta, str)

Source
red(str : String | Char | Nil = nil) : self | String

Alias of #set_color(Color::Red, str)

Source
redbg(str : String | Char | Nil = nil) : self | String

Alias of #set_bg_color(Color::Red, str)

Source
render(str : String | Char) : String

Render a string with ANSI escape codes added

Source
repeat(char : Char | String, len : Int32) : String

Create a string by repeating the char character len times

crayon = Crayon::Text.new
puts crayon.repeat('a', 10)
=> "aaaaaaaaaa"
Source
set_bg_color(color : Color, str : String | Char | Nil = nil) : self | String

Set the current background color

If a string is passed as a second argument, it is encoded with the color applied and returned

crayon = Crayon::Text.new
puts crayon.set_bg_color(Color::Black, "string")
# => "\033[0;40mstring\033[0;m"

If no second argument is passed, the instance is returned, allowing methods to be chained

crayon = Crayon::Text.new
puts crayon.set_bg_color(Color::Black).set_color(Color::Red, "string")
# => "\033[0;40;31mstring\033[0;m"
Source
set_color(color : Color, str : String | Char | Nil = nil) : self | String

Set the current color

If a string is passed as a second argument, it is encoded with the color applied and returned

crayon = Crayon::Text.new
puts crayon.set_color(Color::Black, "string")
# => "\033[0;30mstring\033[0;m"

If no second argument is passed, the instance is returned, allowing methods to be chained

crayon = Crayon::Text.new
puts crayon.set_color(Color::Black).set_bg_color(Color::Red, "string")
# => "\033[0;41;30mstring\033[0;m"
Source
set_style(style : Style, str : String | Char | Nil = nil) : self | String

Set the current style

If a string is passed as a second argument, it is encoded with the color applied and returned

crayon = Crayon::Text.new
puts crayon.set_style(Style::Bold, "string")
# => "\033[1;mstring\033[0;m"

If no second argument is passed, the instance is returned, allowing methods to be chained

crayon = Crayon::Text.new
puts crayon.set_style(Style::Bold).set_color(Color::Red, "string")
# => "\033[0;41;30mstring\033[0;m"
Source
strikethrough(str : String | Char | Nil = nil) : self | String

Alias of #set_style(Style::Strikethrough, str)

Source
strip(str : String | Char) : String

Strip ANSI encoding from a string

crayon = Crayon::Text.new
str    = "\033[0;33mA styled string\033[0;m"
puts crayon.strip "str"
=> "A styled string"
Source
underline(str : String | Char | Nil = nil) : self | String

Alias of #set_style(Style::Underline, str)

Source
white(str : String | Char | Nil = nil) : self | String

Alias of #set_color(Color::White, str)

Source
whitebg(str : String | Char | Nil = nil) : self | String

Alias of #set_bg_color(Color::White, str)

Source
yellow(str : String | Char | Nil = nil) : self | String

Alias of #set_color(Color::Yellow, str)

Source
yellowbg(str : String | Char | Nil = nil) : self | String

Alias of #set_bg_color(Color::Yellow, str)

Source