Class: Exercism::Rb::UI

Inherits:
Object
  • Object
show all
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

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(message)
  paint(message, :bold)
end

#command(message) ⇒ Object



68
69
70
# File 'lib/exercism/rb/ui.rb', line 68

def command(message)
  @out.puts(paint(message, :gray))
end

#error(message) ⇒ Object



64
65
66
# File 'lib/exercism/rb/ui.rb', line 64

def error(message)
  @err.puts("#{paint('error', :red)} #{message}")
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(message)
  @out.puts("#{paint('info', :blue)} #{message}")
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(message = "")
  @out.puts(message)
end

#section(message) ⇒ Object



31
32
33
# File 'lib/exercism/rb/ui.rb', line 31

def section(message)
  @out.puts(paint(message, :cyan))
end

#success(message) ⇒ Object



56
57
58
# File 'lib/exercism/rb/ui.rb', line 56

def success(message)
  @out.puts("#{paint('done', :green)} #{message}")
end

#title(message) ⇒ Object



27
28
29
# File 'lib/exercism/rb/ui.rb', line 27

def title(message)
  @out.puts(bold(message))
end

#warn(message) ⇒ Object



60
61
62
# File 'lib/exercism/rb/ui.rb', line 60

def warn(message)
  @err.puts("#{paint('warn', :yellow)} #{message}")
end