Class: Spoom::Printer
Direct Known Subclasses
Instance Attribute Summary collapse
-
#out ⇒ Object
: (IO | StringIO).
Instance Method Summary collapse
-
#colorize(string, *color) ⇒ Object
Colorize ‘string` with color if `@colors` : (String string, *Spoom::Color color) -> String.
-
#dedent ⇒ Object
Decrease indent level : -> void.
-
#indent ⇒ Object
Increase indent level : -> void.
-
#initialize(out: $stdout, colors: true, indent_level: 0) ⇒ Printer
constructor
: (?out: (IO | StringIO), ?colors: bool, ?indent_level: Integer) -> void.
-
#print(string) ⇒ Object
Print ‘string` into `out` : (String? string) -> void.
-
#print_colored(string, *color) ⇒ Object
Print ‘string` colored with `color` into `out`.
-
#printl(string) ⇒ Object
Print ‘string` with indent and newline : (String? string) -> void.
-
#printn ⇒ Object
Print a new line into ‘out` : -> void.
-
#printt ⇒ Object
Print an indent space into ‘out` : -> void.
Methods included from Colorize
Constructor Details
#initialize(out: $stdout, colors: true, indent_level: 0) ⇒ Printer
: (?out: (IO | StringIO), ?colors: bool, ?indent_level: Integer) -> void
14 15 16 17 18 |
# File 'lib/spoom/printer.rb', line 14 def initialize(out: $stdout, colors: true, indent_level: 0) @out = out @colors = colors @indent_level = indent_level end |
Instance Attribute Details
#out ⇒ Object
: (IO | StringIO)
11 12 13 |
# File 'lib/spoom/printer.rb', line 11 def out @out end |
Instance Method Details
#colorize(string, *color) ⇒ Object
Colorize ‘string` with color if `@colors` : (String string, *Spoom::Color color) -> String
75 76 77 78 79 |
# File 'lib/spoom/printer.rb', line 75 def colorize(string, *color) return string unless @colors T.unsafe(self).set_color(string, *color) end |
#dedent ⇒ Object
Decrease indent level : -> void
28 29 30 |
# File 'lib/spoom/printer.rb', line 28 def dedent @indent_level -= 2 end |
#indent ⇒ Object
Increase indent level : -> void
22 23 24 |
# File 'lib/spoom/printer.rb', line 22 def indent @indent_level += 2 end |
#print(string) ⇒ Object
Print ‘string` into `out` : (String? string) -> void
34 35 36 37 38 |
# File 'lib/spoom/printer.rb', line 34 def print(string) return unless string @out.print(string) end |
#print_colored(string, *color) ⇒ Object
Print ‘string` colored with `color` into `out`
Does not use colors unless ‘@colors`. : (String? string, *Color color) -> void
44 45 46 47 48 49 |
# File 'lib/spoom/printer.rb', line 44 def print_colored(string, *color) return unless string string = T.unsafe(self).colorize(string, *color) @out.print(string) end |
#printl(string) ⇒ Object
Print ‘string` with indent and newline : (String? string) -> void
59 60 61 62 63 64 65 |
# File 'lib/spoom/printer.rb', line 59 def printl(string) return unless string printt print(string) printn end |
#printn ⇒ Object
Print a new line into ‘out` : -> void
53 54 55 |
# File 'lib/spoom/printer.rb', line 53 def printn print("\n") end |
#printt ⇒ Object
Print an indent space into ‘out` : -> void
69 70 71 |
# File 'lib/spoom/printer.rb', line 69 def printt print(" " * @indent_level) end |