From: Sven Strickroth Date: Sat, 07 Jan 2012 04:27:58 GMT Subject: Re: [PATCH 1/2] git-svn, perl/Git.pm: add central method for prompting passwords honoring GIT_ASKPASS and SSH_ASKPASS Message-ID: <4F07C9CE.30905@tu-clausthal.de> In-Reply-To: <7vipkrp9pq.fsf@alter.siamese.dyndns.org> Hi, Am 04.01.2012 20:08 schrieb Junio C Hamano: > Is there a way to ask Term::ReadKey (or possibly some other module) if we > will be able to interact with the terminal _before_ we give that prompt? > > The simplest would be to do this, I would think, but I didn't test it. > > if (!defined $ret && -t) { > print STDERR $prompt; > if ($isPassword) { > ... > } -t does not help, but I think it's not a big deal if the prompt is printed on the terminal and also on the ASKPASS-helper. Using Term::ReadLine seems to help: ... $ret = _prompt($ENV{'SSH_ASKPASS'}, $prompt); } if (!defined $ret) { use Term::Readline; my $term = Term::ReadLine->new("Git.pm"); if ($isPassword) { require Term::ReadKey; Term::ReadKey::ReadMode('noecho'); } $ret = $term->readline($prompt); if ($isPassword) { Term::ReadKey::ReadMode('restore'); print STDERR "\n"; } } if (!defined $ret) { $ret = _prompt($ENV{'SSH_ASKPASS'}, $prompt); ... But I'm not sure if this is what we want, because you can go with the cursor over the whole terminal. A better (working) alternative might be: ... $ret = _prompt($ENV{'SSH_ASKPASS'}, $prompt); } use Term::Readline; my $term = Term::ReadLine->new("Git.pm"); if (!defined $ret && fileno($term->IN)) { print STDERR $prompt; if ($isPassword) { ... } ... -- Best regards, Sven Strickroth ClamAV, a GPL anti-virus toolkit http://www.clamav.net PGP key id F5A9D4C4 @ any key-server