Here is a proof of concept, uses Data::Dump::Streamer and cpan STSI/TermReadKey-2.30.02.tar.gz (or cpanp i STSI/TermReadKey-2.30.02.tar.gz)
use Term::ReadKey;
use strict; use warnings;
my @completion_list = qw[ ro sham bo foo bar baz ];
{
my $orig_prompt = "Hi: ";
my $prompt = $orig_prompt;
my $prev_prompt = $orig_prompt;
my $tab = do {
my $ix = -1;
my $xx = @completion_list - 1;
sub {
$ix++;
return $completion_list[ $ix % $xx ];
};
};
$|=1;
print $prompt;
my $key ;
while( 1 ){
$key = ReadKey(-1);
next unless defined $key;
if( $key eq "\r"){
print "\n";
last;
} elsif( $key eq "\t" ){
my $completion = $tab->();
$prompt = $orig_prompt . $completion;
#~ FAIL print "\b" x ( 1 + length $prev_prompt ), $prompt;
#~ FAIL print "\b" x ( 100 ), $prompt;
#~ FAIL print "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\
+b\b\b\b$prompt";
print "\r" , " " x ( length $prev_prompt );
print "\r", $prompt;
$prev_prompt = $prompt;
} elsif( $key eq "\e") {
print "\r" , " " x ( length $prev_prompt );
$prompt = $orig_prompt ;
print "\r", $prompt;
$prev_prompt = $prompt;
} else {
use DDS; warn Dump $key ;
}
}
use DDS; warn Dump [ $key, $orig_prompt, $prompt, $prev_prompt ] ;
}
It could make a great addition to Term::Interact/example
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|