struct Colorize::Object(T)

Overview

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

Defined in:

colorize.cr

Constructors

Instance Method Summary

Instance methods inherited from struct Struct

==(other) : Bool ==, hash(hasher) hash, inspect(io : IO) : Nil inspect, pretty_print(pp) : Nil pretty_print, to_s(io : IO) : Nil to_s

Instance methods inherited from struct Value

==(other : JSON::Any)
==(other : YAML::Any)
==(other)
==
, dup dup

Instance methods inherited from class Object

! : Bool !, !=(other) !=, !~(other) !~, ==(other) ==, ===(other : JSON::Any)
===(other : YAML::Any)
===(other)
===
, =~(other) =~, as(type : Class) as, as?(type : Class) as?, class class, dup dup, hash(hasher)
hash
hash
, in?(collection : Object) : Bool
in?(*values : Object) : Bool
in?
, inspect(io : IO) : Nil
inspect : String
inspect
, is_a?(type : Class) : Bool is_a?, itself itself, nil? : Bool nil?, not_nil!(message)
not_nil!
not_nil!
, pretty_inspect(width = 79, newline = "\n", indent = 0) : String pretty_inspect, pretty_print(pp : PrettyPrint) : Nil pretty_print, responds_to?(name : Symbol) : Bool responds_to?, tap(&) tap, to_json(io : IO) : Nil
to_json : String
to_json
, to_pretty_json(indent : String = " ") : String
to_pretty_json(io : IO, indent : String = " ") : Nil
to_pretty_json
, to_s(io : IO) : Nil
to_s : String
to_s
, to_yaml(io : IO) : Nil
to_yaml : String
to_yaml
, try(&) try, unsafe_as(type : T.class) forall T unsafe_as

Class methods inherited from class Object

from_json(string_or_io, root : String)
from_json(string_or_io)
from_json
, from_yaml(string_or_io : String | IO) from_yaml

Constructor Detail

def self.new(object : T) #

[View source]

Instance Method Detail

def back(r : UInt8, g : UInt8, b : UInt8) #

[View source]
def back(color : Symbol) : self #

[View source]
def back(back : Color) : self #

[View source]
def back(back : UInt8) #

[View source]
def black #

[View source]
def blink #

Apply text decoration Mode::Blink.


[View source]
def blink_fast #

Apply text decoration Mode::BlinkFast.


[View source]
def blue #

[View source]
def bold #

Apply text decoration Mode::Bold.


[View source]
def bright #

Apply text decoration Mode::Bright.


[View source]
def cyan #

[View source]
def dark_gray #

[View source]
def default #

[View source]
def dim #

Apply text decoration Mode::Dim.


[View source]
def double_underline #

Apply text decoration Mode::DoubleUnderline.


[View source]
def fore(r : UInt8, g : UInt8, b : UInt8) #

[View source]
def fore(color : Symbol) : self #

[View source]
def fore(fore : Color) : self #

[View source]
def fore(fore : UInt8) #

[View source]
def green #

[View source]
def hidden #

Apply text decoration Mode::Hidden.


[View source]
def inspect(io : IO) : Nil #

Inspects this object and makes the ANSI escape codes visible.


[View source]
def italic #

Apply text decoration Mode::Italic.


[View source]
def light_blue #

[View source]
def light_cyan #

[View source]
def light_gray #

[View source]
def light_green #

[View source]
def light_magenta #

[View source]
def light_red #

[View source]
def light_yellow #

[View source]
def magenta #

[View source]
def mode(mode : Mode) : self #

Adds mode to the text's decorations.


[View source]
def on(color : Symbol) #

[View source]
def on_black #

[View source]
def on_blue #

[View source]
def on_cyan #

[View source]
def on_dark_gray #

[View source]
def on_default #

[View source]
def on_green #

[View source]
def on_light_blue #

[View source]
def on_light_cyan #

[View source]
def on_light_gray #

[View source]
def on_light_green #

[View source]
def on_light_magenta #

[View source]
def on_light_red #

[View source]
def on_light_yellow #

[View source]
def on_magenta #

[View source]
def on_red #

[View source]
def on_white #

[View source]
def on_yellow #

[View source]
def overline #

Apply text decoration Mode::Overline.


[View source]
def red #

[View source]
def reverse #

Apply text decoration Mode::Reverse.


[View source]
def strikethrough #

Apply text decoration Mode::Strikethrough.


[View source]
def 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

[View source]
def to_s(io : IO) : Nil #

Appends this object colored and with text decoration to io.


[View source]
def toggle(flag) #

Enables or disables colors and text decoration on this object.


[View source]
def underline #

Apply text decoration Mode::Underline.


[View source]
def white #

[View source]
def yellow #

[View source]