Class: Vagrant::UI::Basic
Overview
This is a UI implementation that outputs the text as is. It doesn't add any color.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Interface
Instance Method Summary collapse
- #ask(message, opts = nil) ⇒ Object
- #clear_line ⇒ Object
-
#format_message(type, message, opts = nil) ⇒ Object
This is called by
say
to format the message for output. -
#report_progress(progress, total, show_parts = true) ⇒ Object
This is used to output progress reports to the UI.
-
#say(type, message, opts = nil) ⇒ Object
This method handles actually outputting a message of a given type to the console.
Methods inherited from Interface
Constructor Details
This class inherits a constructor from Vagrant::UI::Interface
Instance Method Details
#ask(message, opts = nil) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/vagrant/ui.rb', line 51 def ask(, opts=nil) super() # Setup the options so that the new line is suppressed opts ||= {} opts[:new_line] = false if !opts.has_key?(:new_line) opts[:prefix] = false if !opts.has_key?(:prefix) # Output the data say(:info, , opts) # Get the results and chomp off the newline STDIN.gets.chomp end |
#clear_line ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/vagrant/ui.rb', line 78 def clear_line reset = "\r" reset += "\e[0K" unless Util::Platform.windows? reset info(reset, :new_line => false) end |
#format_message(type, message, opts = nil) ⇒ Object
This is called by say
to format the message for output.
105 106 107 108 109 |
# File 'lib/vagrant/ui.rb', line 105 def (type, , opts=nil) opts ||= {} = "[#{@resource}] #{}" if opts[:prefix] end |
#report_progress(progress, total, show_parts = true) ⇒ Object
This is used to output progress reports to the UI.
Send this method progress/total and it will output it
to the UI. Send clear_line
to clear the line to show
a continuous progress meter.
70 71 72 73 74 75 76 |
# File 'lib/vagrant/ui.rb', line 70 def report_progress(progress, total, show_parts=true) percent = (progress.to_f / total.to_f) * 100 line = "Progress: #{percent.to_i}%" line << " (#{progress} / #{total})" if show_parts info(line, :new_line => false) end |
#say(type, message, opts = nil) ⇒ Object
This method handles actually outputting a message of a given type to the console.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/vagrant/ui.rb', line 88 def say(type, , opts=nil) defaults = { :new_line => true, :prefix => true } opts = defaults.merge(opts || {}) # Determine whether we're expecting to output our # own new line or not. printer = opts[:new_line] ? :puts : :print # Determine the proper IO channel to send this message # to based on the type of the message channel = type == :error || opts[:channel] == :error ? $stderr : $stdout # Output! channel.send(printer, (type, , opts)) end |