Module: Mybot::Fmt

Included in:
Cli, Command, Helpers, Node, Recipes, Tasks
Defined in:
lib/mybot/fmt.rb

Constant Summary collapse

WIDTH =
10

Instance Method Summary collapse

Instance Method Details

#asterisks(str) ⇒ Object



48
49
50
# File 'lib/mybot/fmt.rb', line 48

def asterisks(str)
  "*" * str.size
end

#colored(str, *colors) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/mybot/fmt.rb', line 33

def colored(str, *colors)
  if $MYBOT_USE_COLORS
    colors.each do |c|
      str = str.send(c)
    end
    str
  else
    str
  end
end


7
8
9
10
11
# File 'lib/mybot/fmt.rb', line 7

def print_cmd(type, msg, *colors)
  if $MYBOT_SHOW_CMD
    $stdout.print "#{spaces(type)}#{colored(type, *colors)} #{msg.to_s}"
  end
end


13
14
15
# File 'lib/mybot/fmt.rb', line 13

def print_cmd!(type, msg, *colors)
  print_cmd type, "#{msg}\n", *colors
end


25
26
27
28
29
30
31
# File 'lib/mybot/fmt.rb', line 25

def print_progress(n)
  if $MYBOT_SHOW_CMD
    cmd = colored "progress", :blue, :bold
    $stdout.print "\r#{spaces('progress')}#{cmd} #{n}%"
    puts if n == 100
  end
end


21
22
23
# File 'lib/mybot/fmt.rb', line 21

def print_stderr(data, force = false)
  $stdout.print colored(data, :red) if $MYBOT_SHOW_OUTPUT || force
end


17
18
19
# File 'lib/mybot/fmt.rb', line 17

def print_stdout(data, force = false)
  $stdout.print colored(data, :green) if $MYBOT_SHOW_OUTPUT || force
end

#spaces(str) ⇒ Object



44
45
46
# File 'lib/mybot/fmt.rb', line 44

def spaces(str)
  " " * (WIDTH - str.size)
end