Class: Hazetug::UI
- Inherits:
-
Object
- Object
- Hazetug::UI
- Defined in:
- lib/hazetug/ui.rb
Defined Under Namespace
Modules: Mixin
Instance Attribute Summary collapse
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdin ⇒ Object
readonly
Returns the value of attribute stdin.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Class Method Summary collapse
Instance Method Summary collapse
- #color(string, *colors) ⇒ Object
- #color? ⇒ Boolean
- #err(message) ⇒ Object
- #error(message) ⇒ Object
- #fatal(message) ⇒ Object
- #highline ⇒ Object
-
#initialize(stdout, stderr, stdin) ⇒ UI
constructor
A new instance of UI.
- #msg(message) ⇒ Object (also: #info)
- #warn(message) ⇒ Object
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
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
12 13 14 |
# File 'lib/hazetug/ui.rb', line 12 def stderr @stderr end |
#stdin ⇒ Object (readonly)
Returns the value of attribute stdin.
13 14 15 |
# File 'lib/hazetug/ui.rb', line 13 def stdin @stdin end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
11 12 13 |
# File 'lib/hazetug/ui.rb', line 11 def stdout @stdout end |
Class Method Details
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
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() begin stderr.puts 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() err("#{color('ERROR:', :red, :bold)} #{}") end |
#fatal(message) ⇒ Object
54 55 56 |
# File 'lib/hazetug/ui.rb', line 54 def fatal() err("#{color('FATAL:', :red, :bold)} #{}") end |
#highline ⇒ Object
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() begin stdout.puts 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() err("#{color('WARNING:', :yellow, :bold)} #{}") end |