class Pantry::UI

Public Class Methods

new(input = $stdin, output = $stdout) click to toggle source
# File lib/pantry/ui.rb, line 15
def initialize(input = $stdin, output = $stdout)
  require 'highline'
  @output = output
  @input  = input
  @highline = HighLine.new(input, output)
end

Public Instance Methods

color(string, color) click to toggle source
# File lib/pantry/ui.rb, line 32
def color(string, color)
  HighLine.color(string, color)
end
continue?(message) click to toggle source

Show the user a message and ask them to continue by hitting Enter, or they can cancel with “No”

# File lib/pantry/ui.rb, line 38
def continue?(message)
  @highline.agree(message) do |q|
    q.default = "yes"
  end
end
list(array) click to toggle source

Print out a list, attempting to make it look somewhat reasonable

# File lib/pantry/ui.rb, line 28
def list(array)
  say(array.join("\n") + "\n")
end
progress_finish() click to toggle source

Complete and close down the current progress meter

# File lib/pantry/ui.rb, line 63
def progress_finish
  @progress.finish
end
progress_start(tick_count) click to toggle source

Start a new progress meter with the given number of ticks

# File lib/pantry/ui.rb, line 45
def progress_start(tick_count)
  require 'ruby-progressbar'
  @progress = ProgressBar.create(
    total: tick_count, output: @output,
    format: "Progress: %P%% |%B| %c/%C %e"
  )
end
progress_step(tick_count) click to toggle source

Increment the running progress meter the given number of ticks

# File lib/pantry/ui.rb, line 54
def progress_step(tick_count)
  if @progress.progress + tick_count > @progress.total
    tick_count = @progress.total - @progress.progress
  end

  @progress.progress += tick_count
end
say(message) click to toggle source

Send a message to STDOUT

# File lib/pantry/ui.rb, line 23
def say(message)
  @highline.say(message)
end