class Crayon::Text
- Crayon::Text
- Reference
- Object
Defined in:
crayon/text.crConstant Summary
-
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 Method Summary
-
#black(str : String | Char | Nil = nil) : self | String
Alias of
#set_color(Color::Black, str)
-
#blackbg(str : String | Char | Nil = nil) : self | String
Alias of
#set_bg_color(Color::Black, str)
-
#blink(str : String | Char | Nil = nil) : self | String
Alias of
#set_style(Style::Blink, str)
-
#blue(str : String | Char | Nil = nil) : self | String
Alias of
#set_color(Color::Blue, str)
-
#bluebg(str : String | Char | Nil = nil) : self | String
Alias of
#set_bg_color(Color::Blue, str)
-
#bold(str : String | Char | Nil = nil) : self | String
Alias of
#set_style(Style::Bold, str)
-
#cyan(str : String | Char | Nil = nil) : self | String
Alias of
#set_color(Color::Cyan, str)
-
#cyanbg(str : String | Char | Nil = nil) : self | String
Alias of
#set_bg_color(Color::Cyan, str)
-
#encode(str : String | Char) : String
Add ANSI escape codes to a string
-
#green(str : String | Char | Nil = nil) : self | String
Alias of
#set_color(Color::Green, str)
-
#greenbg(str : String | Char | Nil = nil) : self | String
Alias of
#set_bg_color(Color::Green, str)
-
#inverse(str : String | Char | Nil = nil) : self | String
Alias of
#set_style(Style::Inverse, str)
-
#italic(str : String | Char | Nil = nil) : self | String
Alias of
#set_style(Style::Italic, str)
-
#magenta(str : String | Char | Nil = nil) : self | String
Alias of
#set_color(Color::Magenta, str)
-
#magentabg(str : String | Char | Nil = nil) : self | String
Alias of
#set_bg_color(Color::Magenta, str)
-
#red(str : String | Char | Nil = nil) : self | String
Alias of
#set_color(Color::Red, str)
-
#redbg(str : String | Char | Nil = nil) : self | String
Alias of
#set_bg_color(Color::Red, str)
-
#render(str : String | Char) : String
Render a string with ANSI escape codes added
-
#repeat(char : Char | String, len : Int32) : String
Create a string by repeating the char character len times
-
#set_bg_color(color : Color, str : String | Char | Nil = nil) : self | String
Set the current background color
-
#set_color(color : Color, str : String | Char | Nil = nil) : self | String
Set the current color
-
#set_style(style : Style, str : String | Char | Nil = nil) : self | String
Set the current style
- #strikethrough(str : String | Char | Nil = nil) : self | String
-
#strip(str : String | Char) : String
Strip ANSI encoding from a string
-
#underline(str : String | Char | Nil = nil) : self | String
Alias of
#set_style(Style::Underline, str)
-
#white(str : String | Char | Nil = nil) : self | String
Alias of
#set_color(Color::White, str)
-
#whitebg(str : String | Char | Nil = nil) : self | String
Alias of
#set_bg_color(Color::White, str)
-
#yellow(str : String | Char | Nil = nil) : self | String
Alias of
#set_color(Color::Yellow, str)
-
#yellowbg(str : String | Char | Nil = nil) : self | String
Alias of
#set_bg_color(Color::Yellow, str)
Instance Method Detail
Alias of #set_color(Color::Black, str)
Alias of #set_bg_color(Color::Black, str)
Alias of #set_style(Style::Blink, str)
Alias of #set_color(Color::Blue, str)
Alias of #set_bg_color(Color::Blue, str)
Alias of #set_style(Style::Bold, str)
Alias of #set_color(Color::Cyan, str)
Alias of #set_bg_color(Color::Cyan, str)
Alias of #set_color(Color::Green, 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_color(Color::Red, 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"
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_color(Color::White, str)
Alias of #set_bg_color(Color::White, str)
Alias of #set_color(Color::Yellow, str)
Alias of #set_bg_color(Color::Yellow, str)