Skip to content

Commit

Permalink
Merge branch 'tr/add-i-no-escape'
Browse files Browse the repository at this point in the history
* tr/add-i-no-escape:
  add -i: ignore terminal escape sequences
  • Loading branch information
gitster committed May 23, 2011
2 parents 34ad5a5 + b5cc003 commit 4961210
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions git-add--interactive.perl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
my $normal_color = $repo->get_color("", "reset");

my $use_readkey = 0;
my $use_termcap = 0;
my %term_escapes;

sub ReadMode;
sub ReadKey;
if ($repo->config_bool("interactive.singlekey")) {
Expand All @@ -53,6 +56,14 @@
Term::ReadKey->import;
$use_readkey = 1;
};
eval {
require Term::Cap;
my $termcap = Term::Cap->Tgetent;
foreach (values %$termcap) {
$term_escapes{$_} = 1 if /^\e/;
}
$use_termcap = 1;
};
}

sub colored {
Expand Down Expand Up @@ -1067,6 +1078,14 @@ sub prompt_single_character {
ReadMode 'cbreak';
my $key = ReadKey 0;
ReadMode 'restore';
if ($use_termcap and $key eq "\e") {
while (!defined $term_escapes{$key}) {
my $next = ReadKey 0.5;
last if (!defined $next);
$key .= $next;
}
$key =~ s/\e/^[/;
}
print "$key" if defined $key;
print "\n";
return $key;
Expand Down

0 comments on commit 4961210

Please sign in to comment.