Permalink
Browse files

Merge remote branch 'erikh/windows-silentui-hack'

  • Loading branch information...
2 parents a2a8823 + adff87c commit c2d6cd504dc82d9bb5fa95d0d23df58dca400332 @luislavena luislavena committed Mar 1, 2011
Showing with 40 additions and 9 deletions.
  1. +1 −1 lib/rubygems/mock_gem_ui.rb
  2. +28 −7 lib/rubygems/user_interaction.rb
  3. +11 −1 test/rubygems/test_gem_stream_ui.rb
@@ -31,7 +31,7 @@ def initialize(input = "")
outs.extend TTY
errs.extend TTY
- super ins, outs, errs
+ super ins, outs, errs, true
@terminated = false
end
@@ -132,10 +132,19 @@ class Gem::StreamUI
attr_reader :ins, :outs, :errs
- def initialize(in_stream, out_stream, err_stream=STDERR)
+ def initialize(in_stream, out_stream, err_stream=STDERR, usetty=true)
@ins = in_stream
@outs = out_stream
@errs = err_stream
+ @usetty = usetty
+ end
+
+ def tty?
+ if RUBY_PLATFORM =~ /mingw|mswin/
+ @usetty
+ else
+ @usetty && @ins.tty?
+ end
end
##
@@ -167,7 +176,7 @@ def choose_from_list(question, list)
# default.
def ask_yes_no(question, default=nil)
- unless @ins.tty? then
+ unless tty? then
if default.nil? then
raise Gem::OperationNotSupportedError,
"Not connected to a tty and no default specified"
@@ -203,7 +212,7 @@ def ask_yes_no(question, default=nil)
# Ask a question. Returns an answer if connected to a tty, nil otherwise.
def ask(question)
- return nil if not @ins.tty?
+ return nil if not tty?
@outs.print(question + " ")
@outs.flush
@@ -218,7 +227,7 @@ def ask(question)
# Ask for a password. Does not echo response to terminal.
def ask_for_password(question)
- return nil if not @ins.tty?
+ return nil if not tty?
require 'io/console'
@@ -234,7 +243,7 @@ def ask_for_password(question)
# Ask for a password. Does not echo response to terminal.
def ask_for_password(question)
- return nil if not @ins.tty?
+ return nil if not tty?
@outs.print(question + " ")
@outs.flush
@@ -246,6 +255,8 @@ def ask_for_password(question)
# Asks for a password that works on windows. Ripped from the Heroku gem.
def ask_for_password_on_windows
+ return nil if not tty?
+
require "Win32API"
char = nil
password = ''
@@ -267,6 +278,8 @@ def ask_for_password_on_windows
# Asks for a password that works on unix
def ask_for_password_on_unix
+ return nil if not tty?
+
system "stty -echo"
password = @ins.gets
password.chomp! if password
@@ -327,6 +340,10 @@ def terminate_interaction(status = 0)
# Return a progress reporter object chosen from the current verbosity.
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)
@@ -429,6 +446,10 @@ def done
# Return a download reporter object chosen from the current verbosity
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)
@@ -512,7 +533,7 @@ def update_display(show_progress = true, new_line = false)
class Gem::ConsoleUI < Gem::StreamUI
def initialize
- super STDIN, STDOUT, STDERR
+ super STDIN, STDOUT, STDERR, true
end
end
@@ -531,7 +552,7 @@ def initialize
writer = File.open('nul', 'w')
end
- super reader, writer, writer
+ super reader, writer, writer, false
end
def download_reporter(*args)
@@ -31,10 +31,12 @@ def setup
@in.extend IsTty
@out.extend IsTty
- @sui = Gem::StreamUI.new @in, @out, @err
+ @sui = Gem::StreamUI.new @in, @out, @err, true
end
def test_ask
+ skip 'TTY detection broken on windows' if Gem.win_platform?
+
timeout(1) do
expected_answer = "Arthur, King of the Britons"
@in.string = "#{expected_answer}\n"
@@ -44,6 +46,8 @@ def test_ask
end
def test_ask_no_tty
+ skip 'TTY handling is broken on windows' if Gem.win_platform?
+
@in.tty = false
timeout(0.1) do
@@ -64,6 +68,8 @@ def test_ask_for_password
end
def test_ask_for_password_no_tty
+ skip 'TTY handling is broken on windows' if Gem.win_platform?
+
@in.tty = false
timeout(0.1) do
@@ -73,6 +79,8 @@ def test_ask_for_password_no_tty
end
def test_ask_yes_no_no_tty_with_default
+ skip 'TTY handling is broken on windows' if Gem.win_platform?
+
@in.tty = false
timeout(0.1) do
@@ -85,6 +93,8 @@ def test_ask_yes_no_no_tty_with_default
end
def test_ask_yes_no_no_tty_without_default
+ skip 'TTY handling is broken on windows' if Gem.win_platform?
+
@in.tty = false
timeout(0.1) do

0 comments on commit c2d6cd5

Please sign in to comment.