add -p: avoid use of undefined $key when ReadKey -> EOF
b5cc003253
(add -i: ignore terminal escape sequences, 2011-05-17) add an additional check to the original code to better handle keys for escape sequences, but failed to account for the possibility the first ReadKey call returned undef (ex: stdin closes) and that was being handled fine by the original code inca6ac7f135
(add -p: prompt for single characters, 2009-02-05) Add a test for undefined and encapsulate the loop and the original print that relied on it within it. After this, the following command (in a suitable repository state) wouldn't print any error: $ git -c interactive.singleKey add -p </dev/null Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
94f6e3e283
commit
fc8a8126df
@ -1175,15 +1175,17 @@ sub prompt_single_character {
|
|||||||
ReadMode 'cbreak';
|
ReadMode 'cbreak';
|
||||||
my $key = ReadKey 0;
|
my $key = ReadKey 0;
|
||||||
ReadMode 'restore';
|
ReadMode 'restore';
|
||||||
if ($use_termcap and $key eq "\e") {
|
if (defined $key) {
|
||||||
while (!defined $term_escapes{$key}) {
|
if ($use_termcap and $key eq "\e") {
|
||||||
my $next = ReadKey 0.5;
|
while (!defined $term_escapes{$key}) {
|
||||||
last if (!defined $next);
|
my $next = ReadKey 0.5;
|
||||||
$key .= $next;
|
last if (!defined $next);
|
||||||
|
$key .= $next;
|
||||||
|
}
|
||||||
|
$key =~ s/\e/^[/;
|
||||||
}
|
}
|
||||||
$key =~ s/\e/^[/;
|
print "$key";
|
||||||
}
|
}
|
||||||
print "$key" if defined $key;
|
|
||||||
print "\n";
|
print "\n";
|
||||||
return $key;
|
return $key;
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user