Gem::StreamUI implements a simple stream based user interface.
- CLASS Gem::StreamUI::SilentDownloadReporter
- CLASS Gem::StreamUI::SilentProgressReporter
- CLASS Gem::StreamUI::SimpleProgressReporter
- CLASS Gem::StreamUI::VerboseDownloadReporter
- CLASS Gem::StreamUI::VerboseProgressReporter
- A
- B
- C
- D
- N
- P
- S
- T
[R] | errs | |
[R] | ins | |
[R] | outs |
Display an informational alert. Will ask question
if it is
not nil.
Display an error message in a location expected to get error messages. Will
ask question
if it is not nil.
Display a warning in a location expected to get error messages. Will ask
question
if it is not nil.
Ask a question. Returns an answer if connected to a tty, nil otherwise.
Ask for a password. Does not echo response to terminal.
Asks for a password that works on unix
Asks for a password that works on windows. Ripped from the Heroku gem.
# File lib/rubygems/user_interaction.rb, line 263 def ask_for_password_on_windows return nil if not tty? require "Win32API" char = nil password = '' while char = Win32API.new("crtdll", "_getch", [ ], "L").Call do break if char == 10 || char == 13 # received carriage return or newline if char == 127 || char == 8 # backspace and delete password.slice!(-1, 1) else password << char.chr end end puts password end
Ask a question. Returns a true for yes, false for no. If not connected to a tty, raises an exception if default is nil, otherwise returns default.
# File lib/rubygems/user_interaction.rb, line 184 def ask_yes_no(question, default=nil) unless tty? then if default.nil? then raise Gem::OperationNotSupportedError, "Not connected to a tty and no default specified" else return default end end default_answer = case default when nil 'yn' when true 'Yn' else 'yN' end result = nil while result.nil? do result = case ask "#{question} [#{default_answer}]" when /^y/i then true when /^n/i then false when /^$/ then default else nil end end return result end
Prints a formatted backtrace to the errors stream if backtraces are enabled.
Choose from a list of options. question
is a prompt displayed
above the list. list
is a list of option strings. Returns
the pair [option_name, option_index].
# File lib/rubygems/user_interaction.rb, line 161 def choose_from_list(question, list) @outs.puts question list.each_with_index do |item, index| @outs.puts " #{index+1}. #{item}" end @outs.print "> " @outs.flush result = @ins.gets return nil, nil unless result result = result.strip.to_i - 1 return list[result], result end
Display a debug message on the same location as error messages.
Return a download reporter object chosen from the current verbosity
# File lib/rubygems/user_interaction.rb, line 454 def download_reporter(*args) if self.kind_of?(Gem::SilentUI) return SilentDownloadReporter.new(@outs, *args) end case Gem.configuration.verbose when nil, false SilentDownloadReporter.new(@outs, *args) else VerboseDownloadReporter.new(@outs, *args) end end
Return a progress reporter object chosen from the current verbosity.
# File lib/rubygems/user_interaction.rb, line 348 def progress_reporter(*args) if self.kind_of?(Gem::SilentUI) return SilentProgressReporter.new(@outs, *args) end case Gem.configuration.verbose when nil, false SilentProgressReporter.new(@outs, *args) when true SimpleProgressReporter.new(@outs, *args) else VerboseProgressReporter.new(@outs, *args) end end
Display a statement.
Terminate the application with exit code status
, running any
exit handlers that might have been defined.