[Rubygems-developers] Anothor UI wrinkle.

Hugh Sasse hgs at dmu.ac.uk
Tue Jul 12 07:40:19 EDT 2005


On Tue, 12 Jul 2005, Hugh Sasse wrote:

> Also, when doing an install of rails on a PC I get requests for
> prerequisites with the form
>    thingumybob [Yn]
> as the the prompt.  I presumed that the upper case meant default,
> but this did seem to be defined.  Would it make sense to allow 'a'
> for All prerequisites for this gem?

Maybe something like:

--- ./user_interaction.rb.orig  2004-08-27 19:35:32.000000000 +0100
+++ ./user_interaction.rb       2005-07-12 12:36:51.540093000 +0100
@@ -116,6 +116,52 @@
        end
        return result
      end
+
+    # Ask yes, no, skip all, or all or quit.
+    # Returns a true for yes, false for no, :skip for skip,
+    # :all, for all and  :quit for quit (if quit param is true).
+    def ask_yes_no_all(question, default=nil, quit = false)
+      qstr = case default
+      when nil
+        'ynasq'
+      when true
+        'Ynasq'
+      when false
+        'yNasq'
+      when :all
+        'ynAsq'
+      when :skip
+        'ynaSq'
+      when :quit
+        'ynasQ'
+      end
+      qstr.sub!(/q/i, '') unless quit
+
+      result = nil
+      say " y = yes (once), n = no (once), ..."
+      say " a = yes to all , s = skip (i.e. no) to all."
+      say " q = quit" if quit
+      say "Capitalisation signifies default""
+      while result.nil?
+        result = ask("#{question} [#{qstr}]")
+        result = case result
+        when /^y.*/i
+          true
+        when /^n.*/i
+          false
+        when /^a.*/i
+          :all
+        when /^s.*/i
+          :skip
+        when /^q.*/i
+          :quit if quit
+        else
+          default
+        end
+      end
+      return result
+    end
+

      # Ask a question.  Returns an answer.
      def ask(question)


As yet untested.....

         Hugh


More information about the Rubygems-developers mailing list