Gem::StreamUI
implements a simple stream based user interface.
- CLASS Gem::StreamUI::SilentDownloadReporter
- CLASS Gem::StreamUI::SilentProgressReporter
- CLASS Gem::StreamUI::SimpleProgressReporter
- CLASS Gem::StreamUI::ThreadedDownloadReporter
- CLASS Gem::StreamUI::VerboseProgressReporter
- #
- A
- B
- C
- D
- N
- P
- R
- S
- T
Attributes
[R] | errs | The error stream |
[R] | ins | The input stream |
[R] | outs | The output stream |
Class Public methods
new(in_stream, out_stream, err_stream=$stderr, usetty=true) Link
Creates a new StreamUI
wrapping in_stream
for user input, out_stream
for standard output, err_stream
for error output. If usetty
is true then special operations (like asking for passwords) will use the TTY commands to disable character echo.
Instance Public methods
_gets_noecho() Link
alert(statement, question=nil) Link
Display an informational alert. Will ask question
if it is not nil.
alert_error(statement, question=nil) Link
Display an error message in a location expected to get error messages. Will ask question
if it is not nil.
alert_warning(statement, question=nil) Link
Display a warning on stderr. Will ask question
if it is not nil.
ask(question) Link
Ask a question. Returns an answer if connected to a tty, nil otherwise.
ask_for_password(question) Link
Ask for a password. Does not echo response to terminal.
ask_yes_no(question, default=nil) Link
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 ruby/lib/rubygems/user_interaction.rb, line 249 def ask_yes_no(question, default=nil) unless tty? if default.nil? 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 end end result end
backtrace(exception) Link
Prints a formatted backtrace to the errors stream if backtraces are enabled.
choose_from_list(question, list) Link
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 ruby/lib/rubygems/user_interaction.rb, line 225 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 nil, nil unless (0...list.size) === result [list[result], result] end
close() Link
download_reporter(*args) Link
Return a download reporter object chosen from the current verbosity
progress_reporter(*args) Link
Return a progress reporter object chosen from the current verbosity.
# File ruby/lib/rubygems/user_interaction.rb, line 372 def progress_reporter(*args) case Gem.configuration.verbose when nil, false SilentProgressReporter.new(@outs, *args) when true SimpleProgressReporter.new(@outs, *args) else VerboseProgressReporter.new(@outs, *args) end end
require_io_console() Link
say(statement="") Link
Display a statement.
terminate_interaction(status = 0) Link
Terminate the application with exit code status
, running any exit handlers that might have been defined.