Crayon::Text
Inherits Reference < Object
Constants
ANSI escape codes for the end of the string
ANSI escape codes for the start of the string
Instance methods
Alias of #set_bg_color(Color::Black, str)
Alias of #set_bg_color(Color::Blue, str)
Alias of #set_bg_color(Color::Cyan, str)
Alias of #set_bg_color(Color::Green, str)
Alias of #set_style(Style::Inverse, str)
Alias of #set_style(Style::Italic, str)
Alias of #set_color(Color::Magenta, str)
Alias of #set_bg_color(Color::Magenta, str)
Alias of #set_bg_color(Color::Red, str)
Create a string by repeating the char character len times
crayon = Crayon::Text.new
puts crayon.repeat('a', 10)
=> "aaaaaaaaaa"
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"
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"
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"
Alias of #set_style(Style::Strikethrough, str)
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"
Alias of #set_style(Style::Underline, str)
Alias of #set_bg_color(Color::White, str)
Alias of #set_color(Color::Yellow, str)
Alias of #set_bg_color(Color::Yellow, str)