Class: Gitstart::UI

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

Instance Method Summary collapse

Constructor Details

#initialize(io = nil, verbose = false) ⇒ UI

Returns a new instance of UI.



15
16
17
18
19
20
# File 'lib/gitstart.rb', line 15

def initialize(io = nil, verbose = false)
  @io = io
  @verbose = verbose
  @indent_string = "\t"
  @indent_level = 0
end

Instance Method Details

#abort(msg) ⇒ Object



45
46
47
# File 'lib/gitstart.rb', line 45

def abort(msg)
  @io && Kernel.abort("gitstart: #{msg}")
end

#indentObject



22
23
24
# File 'lib/gitstart.rb', line 22

def indent
  @indent_level += 1
end

#puts(*args) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/gitstart.rb', line 32

def puts(*args)
  return unless @io

  if args.empty?
    @io.puts ""
  else
    args.each { |msg| @io.puts("#{@indent_string * @indent_level}#{msg}") }
  end

  @io.flush
  nil
end

#unindentObject



26
27
28
29
30
# File 'lib/gitstart.rb', line 26

def unindent
  if @indent_level > 0
    @indent_level -= 1
  end
end

#vputs(*args) ⇒ Object



49
50
51
# File 'lib/gitstart.rb', line 49

def vputs(*args)
  puts(*args) if @verbose
end