Class: Inch::Utils::UI

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

Direct Known Subclasses

BufferedUI

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stdout = $stdout, stderr = $stderr) ⇒ UI

Returns a new instance of UI



8
9
10
# File 'lib/inch/utils/ui.rb', line 8

def initialize(stdout = $stdout, stderr = $stderr)
  @out, @err = stdout, stderr
end

Instance Attribute Details

#errObject (readonly)

Returns the value of attribute err



6
7
8
# File 'lib/inch/utils/ui.rb', line 6

def err
  @err
end

#outObject (readonly)

Returns the value of attribute out



6
7
8
# File 'lib/inch/utils/ui.rb', line 6

def out
  @out
end

Instance Method Details

#debug(msg) ⇒ Object



12
13
14
15
16
17
# File 'lib/inch/utils/ui.rb', line 12

def debug(msg)
  return unless ENV['DEBUG']
  msg.to_s.lines.each do |line|
    trace edged :dark, line.gsub(/\n$/, '').dark
  end
end

#edged(color, msg, edge = '┃ ') ⇒ Object



24
25
26
# File 'lib/inch/utils/ui.rb', line 24

def edged(color, msg, edge = '')
  trace __edged(color, msg, edge)
end

#header(text, color, bg_color = nil) ⇒ Object



45
46
47
48
49
# File 'lib/inch/utils/ui.rb', line 45

def header(text, color, bg_color = nil)
  @current_header_color = color
  trace __header(text, color, bg_color)
  trace unless use_color?
end

#sub(msg = '') ⇒ Object



19
20
21
22
# File 'lib/inch/utils/ui.rb', line 19

def sub(msg = '')
  color = @current_header_color || :white
  trace __edged(color, msg)
end

#trace(text = '') ⇒ void

This method returns an undefined value.

Writes the given text to out

Parameters:

  • text (String) (defaults to: '')


32
33
34
35
# File 'lib/inch/utils/ui.rb', line 32

def trace(text = '')
  @current_header_color = nil if text.to_s.empty?
  out.puts text
end

#use_color?Boolean

Returns true if the UI uses coloring

Returns:

  • (Boolean)

    true if the UI uses coloring



52
53
54
# File 'lib/inch/utils/ui.rb', line 52

def use_color?
  Term::ANSIColor.coloring?
end

#warn(text = '') ⇒ void

This method returns an undefined value.

Writes the given text to err

Parameters:

  • text (String) (defaults to: '')


41
42
43
# File 'lib/inch/utils/ui.rb', line 41

def warn(text = '')
  err.puts text
end