Class: Hazetug::UI

Inherits:
Object
  • Object
show all
Defined in:
lib/hazetug/ui.rb

Defined Under Namespace

Modules: Mixin

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stdout, stderr, stdin) ⇒ UI

Returns a new instance of UI.



15
16
17
# File 'lib/hazetug/ui.rb', line 15

def initialize(stdout, stderr, stdin)
  @stdout, @stderr, @stdin = stdout, stderr, stdin
end

Instance Attribute Details

#stderrObject (readonly)

Returns the value of attribute stderr.



12
13
14
# File 'lib/hazetug/ui.rb', line 12

def stderr
  @stderr
end

#stdinObject (readonly)

Returns the value of attribute stdin.



13
14
15
# File 'lib/hazetug/ui.rb', line 13

def stdin
  @stdin
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



11
12
13
# File 'lib/hazetug/ui.rb', line 11

def stdout
  @stdout
end

Class Method Details

.instanceObject



70
71
72
# File 'lib/hazetug/ui.rb', line 70

def self.instance
  @instance ||= Hazetug::UI.new(STDOUT, STDERR, STDIN)
end

Instance Method Details

#color(string, *colors) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/hazetug/ui.rb', line 58

def color(string, *colors)
  if color?
    highline.color(string, *colors)
  else
    string
  end
end

#color?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/hazetug/ui.rb', line 66

def color?
  stdout.tty?
end

#err(message) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/hazetug/ui.rb', line 37

def err(message)
  begin
    stderr.puts message
  rescue Errno::EPIPE => e
    raise e
    exit 0
  end
end

#error(message) ⇒ Object



50
51
52
# File 'lib/hazetug/ui.rb', line 50

def error(message)
  err("#{color('ERROR:', :red, :bold)} #{message}")
end

#fatal(message) ⇒ Object



54
55
56
# File 'lib/hazetug/ui.rb', line 54

def fatal(message)
  err("#{color('FATAL:', :red, :bold)} #{message}")
end

#highlineObject



19
20
21
22
23
24
# File 'lib/hazetug/ui.rb', line 19

def highline
  @highline ||= begin
    require 'highline'
    HighLine.new
  end
end

#msg(message) ⇒ Object Also known as: info



26
27
28
29
30
31
32
33
# File 'lib/hazetug/ui.rb', line 26

def msg(message)
  begin
    stdout.puts message
  rescue Errno::EPIPE => e
    raise e
    exit 0
  end
end

#warn(message) ⇒ Object



46
47
48
# File 'lib/hazetug/ui.rb', line 46

def warn(message)
  err("#{color('WARNING:', :yellow, :bold)} #{message}")
end