Class: Pantry::UI
- Inherits:
-
Object
- Object
- Pantry::UI
- Defined in:
- lib/pantry/ui.rb
Instance Method Summary collapse
- #color(string, color) ⇒ Object
-
#continue?(message) ⇒ Boolean
Show the user a message and ask them to continue by hitting Enter, or they can cancel with “No”.
-
#initialize(input = $stdin, output = $stdout) ⇒ UI
constructor
A new instance of UI.
-
#list(array) ⇒ Object
Print out a list, attempting to make it look somewhat reasonable.
-
#progress_finish ⇒ Object
Complete and close down the current progress meter.
-
#progress_start(tick_count) ⇒ Object
Start a new progress meter with the given number of ticks.
-
#progress_step(tick_count) ⇒ Object
Increment the running progress meter the given number of ticks.
-
#say(message) ⇒ Object
Send a message to STDOUT.
Constructor Details
#initialize(input = $stdin, output = $stdout) ⇒ UI
Returns a new instance of UI.
15 16 17 18 19 20 |
# 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 |
Instance Method Details
#color(string, color) ⇒ Object
32 33 34 |
# File 'lib/pantry/ui.rb', line 32 def color(string, color) HighLine.color(string, color) end |
#continue?(message) ⇒ Boolean
Show the user a message and ask them to continue by hitting Enter, or they can cancel with “No”
38 39 40 41 42 |
# File 'lib/pantry/ui.rb', line 38 def continue?() @highline.agree() do |q| q.default = "yes" end end |
#list(array) ⇒ Object
Print out a list, attempting to make it look somewhat reasonable
28 29 30 |
# File 'lib/pantry/ui.rb', line 28 def list(array) say(array.join("\n") + "\n") end |
#progress_finish ⇒ Object
Complete and close down the current progress meter
63 64 65 |
# File 'lib/pantry/ui.rb', line 63 def progress_finish @progress.finish end |
#progress_start(tick_count) ⇒ Object
Start a new progress meter with the given number of ticks
45 46 47 48 49 50 51 |
# 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) ⇒ Object
Increment the running progress meter the given number of ticks
54 55 56 57 58 59 60 |
# 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) ⇒ Object
Send a message to STDOUT
23 24 25 |
# File 'lib/pantry/ui.rb', line 23 def say() @highline.say() end |