From 955b6aa5b5f2c0deacccd04e4006da218c464e39 Mon Sep 17 00:00:00 2001 From: Stuart Nelson Date: Wed, 23 Oct 2013 09:49:40 -0400 Subject: [PATCH] Use `noecho` method for password prompt if available It will be available on Ruby >= 1.9 --- lib/hub/github_api.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/hub/github_api.rb b/lib/hub/github_api.rb index 9b20ca679..039a664b0 100644 --- a/lib/hub/github_api.rb +++ b/lib/hub/github_api.rb @@ -431,10 +431,23 @@ def prompt_auth_code File.exist?('/dev/null') ? '/dev/null' : 'NUL' def askpass + noecho $stdin do |input| + input.gets.chomp + end + end + + def noecho io + require 'io/console' + io.noecho { yield io } + rescue LoadError + fallback_noecho io + end + + def fallback_noecho io tty_state = `stty -g 2>#{NULL}` system 'stty raw -echo -icanon isig' if $?.success? pass = '' - while char = getbyte($stdin) and !(char == 13 or char == 10) + while char = getbyte(io) and !(char == 13 or char == 10) if char == 127 or char == 8 pass[-1,1] = '' unless pass.empty? else