diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2019-12-19 16:22:39 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2019-12-19 16:22:39 -0700 |
commit | b0eb782d0396292a5060d47e6023279191b3a80d (patch) | |
tree | f9d902662d52b828444a8e02cd08a3e6ebf27305 /lib | |
parent | d55411ca1f8b8c465d82e4daa6cd0e60f6359f3a (diff) | |
download | dotfiles-b0eb782d0396292a5060d47e6023279191b3a80d.tar.gz |
use Term::ReadKey in annex-review-unused
Diffstat (limited to 'lib')
-rw-r--r-- | lib/perl5/Local/MrRepo/Repo/Git/Annex.pm | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/lib/perl5/Local/MrRepo/Repo/Git/Annex.pm b/lib/perl5/Local/MrRepo/Repo/Git/Annex.pm index 09d1e5da..3d80c827 100644 --- a/lib/perl5/Local/MrRepo/Repo/Git/Annex.pm +++ b/lib/perl5/Local/MrRepo/Repo/Git/Annex.pm @@ -151,20 +151,30 @@ sub review_unused { if ($opts{interactive}) { my $response; while (1) { + # before prompting, clear out stdin, to avoid + # registered a keypress more than once + ReadMode 4; + while (defined ReadKey(-1)) {} + # would be good if user could say 'b' to go back # to the previous entry. would probably have to # implement this by replacing the foreach loop # with a while loop with a manually maintained # array index into @unused_files. - # - # would also be good not to require the user to - # hit RET, possibly by using Term::ReadKey (see - # example code in its POD). - # - # if do that, add a small delay before accepting - # the next keypress, to reduce the chance of two - # keypresses being accidentally registered - $response = lc(prompt("Drop this unused file? (y/n/o)")); + print "Drop this unused file? (y/n/o) "; + + # Term::ReadKey docs recommend ReadKey(-1) but + # that means we need an infinite loop calling + # ReadKey(-1) over and over, which ramps up system + # load + my $response = ReadKey(0); + ReadMode 0; + print "\n"; + + # respond to C-c + exit 0 if ord($response) == 3; + + $response = lc($response); if ($response eq 'y') { push @to_drop, $unused_file->{number}; last; |