struct

Colorize::Object(T)

Inherits Struct / Value / Object

A colorized object. Colors and text decorations can be modified.

Constructors

new(object : T)
Source

Instance methods

ansi_escape(io : IO) : Nil

Same as ansi_escape but writes to a given io.

Source
ansi_escape

Prints the ANSI escape codes for an object. Note that this has no effect on a Colorize::Object with content, only the escape codes.

require "colorize"

Colorize.with.red.ansi_escape        # => "\e[31m"
"hello world".green.bold.ansi_escape # => "\e[32;1m"
Source
back(r : UInt8, g : UInt8, b : UInt8)
Source
back(color : Symbol) : self
Source
back(back : Color) : self
Source
back(back : UInt8)
Source
black
Source
blue
Source
bold

Apply text decoration Mode::Bold.

Source
bright

Apply text decoration Mode::Bright.

Source
cyan
Source
dark_gray
Source
default
Source
dim

Apply text decoration Mode::Dim.

Source
double_underline

Apply text decoration Mode::DoubleUnderline.

Source
fore(r : UInt8, g : UInt8, b : UInt8)
Source
fore(color : Symbol) : self
Source
fore(fore : Color) : self
Source
fore(fore : UInt8)
Source
green
Source
hidden

Apply text decoration Mode::Hidden.

Source
inspect(io : IO) : Nil

Inspects this object and makes the ANSI escape codes visible.

Source
italic

Apply text decoration Mode::Italic.

Source
light_blue
Source
light_cyan
Source
light_gray
Source
light_green
Source
light_magenta
Source
light_red
Source
light_yellow
Source
magenta
Source
mode(mode : Mode) : self

Adds mode to the text's decorations.

Source
on(color : Symbol)
Source
on_black
Source
on_blue
Source
on_cyan
Source
on_dark_gray
Source
on_default
Source
on_green
Source
on_light_blue
Source
on_light_cyan
Source
on_light_gray
Source
on_light_green
Source
on_light_magenta
Source
on_light_red
Source
on_light_yellow
Source
on_magenta
Source
on_red
Source
on_white
Source
on_yellow
Source
overline

Apply text decoration Mode::Overline.

Source
reverse

Apply text decoration Mode::Reverse.

Source
strikethrough

Apply text decoration Mode::Strikethrough.

Source
surround(io = STDOUT, &)

Surrounds io by the ANSI escape codes and lets you build colored strings:

require "colorize"

io = IO::Memory.new

Colorize.with.red.surround(io) do
  io << "colorful"
  Colorize.with.green.bold.surround(io) do
    io << " hello "
  end
  Colorize.with.blue.surround(io) do
    io << "world"
  end
  io << " string"
end

io.to_s # returns a colorful string where "colorful" is red, "hello" green, "world" blue and " string" red again
Source
to_s(io : IO) : Nil

Appends this object colored and with text decoration to io.

Source
toggle(flag)

Enables or disables colors and text decoration on this object.

Source
underline

Apply text decoration Mode::Underline.

Source
white
Source
yellow
Source