Class: Exercism::Rb::UI
- Inherits:
-
Object
- Object
- Exercism::Rb::UI
- Defined in:
- lib/exercism/rb/ui.rb
Constant Summary collapse
- COLORS =
{ blue: "\e[34m", cyan: "\e[36m", green: "\e[32m", red: "\e[31m", yellow: "\e[33m", gray: "\e[90m", bold: "\e[1m", reset: "\e[0m" }.freeze
Instance Method Summary collapse
- #bold(message) ⇒ Object
- #command(message) ⇒ Object
- #error(message) ⇒ Object
- #highlight(value) ⇒ Object
- #info(message) ⇒ Object
-
#initialize(out: $stdout, err: $stderr, color: nil) ⇒ UI
constructor
A new instance of UI.
- #key_value(key, value, width: 8) ⇒ Object
- #muted(value) ⇒ Object
- #path(value) ⇒ Object
- #say(message = "") ⇒ Object
- #section(message) ⇒ Object
- #success(message) ⇒ Object
- #title(message) ⇒ Object
- #warn(message) ⇒ Object
Constructor Details
#initialize(out: $stdout, err: $stderr, color: nil) ⇒ UI
Returns a new instance of UI.
17 18 19 20 21 |
# File 'lib/exercism/rb/ui.rb', line 17 def initialize(out: $stdout, err: $stderr, color: nil) @out = out @err = err @color = color.nil? ? default_color? : color end |
Instance Method Details
#bold(message) ⇒ Object
72 73 74 |
# File 'lib/exercism/rb/ui.rb', line 72 def bold() paint(, :bold) end |
#command(message) ⇒ Object
68 69 70 |
# File 'lib/exercism/rb/ui.rb', line 68 def command() @out.puts(paint(, :gray)) end |
#error(message) ⇒ Object
64 65 66 |
# File 'lib/exercism/rb/ui.rb', line 64 def error() @err.puts("#{paint('error', :red)} #{}") end |
#highlight(value) ⇒ Object
44 45 46 |
# File 'lib/exercism/rb/ui.rb', line 44 def highlight(value) paint(value, :bold) end |
#info(message) ⇒ Object
52 53 54 |
# File 'lib/exercism/rb/ui.rb', line 52 def info() @out.puts("#{paint('info', :blue)} #{}") end |
#key_value(key, value, width: 8) ⇒ Object
35 36 37 38 |
# File 'lib/exercism/rb/ui.rb', line 35 def key_value(key, value, width: 8) label = key.to_s.ljust(width) @out.puts("#{paint(label, :gray)} #{value}") end |
#muted(value) ⇒ Object
48 49 50 |
# File 'lib/exercism/rb/ui.rb', line 48 def muted(value) paint(value, :gray) end |
#path(value) ⇒ Object
40 41 42 |
# File 'lib/exercism/rb/ui.rb', line 40 def path(value) paint(value, :blue) end |
#say(message = "") ⇒ Object
23 24 25 |
# File 'lib/exercism/rb/ui.rb', line 23 def say( = "") @out.puts() end |
#section(message) ⇒ Object
31 32 33 |
# File 'lib/exercism/rb/ui.rb', line 31 def section() @out.puts(paint(, :cyan)) end |
#success(message) ⇒ Object
56 57 58 |
# File 'lib/exercism/rb/ui.rb', line 56 def success() @out.puts("#{paint('done', :green)} #{}") end |
#title(message) ⇒ Object
27 28 29 |
# File 'lib/exercism/rb/ui.rb', line 27 def title() @out.puts(bold()) end |
#warn(message) ⇒ Object
60 61 62 |
# File 'lib/exercism/rb/ui.rb', line 60 def warn() @err.puts("#{paint('warn', :yellow)} #{}") end |