Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Using Tab Completion on Windows in cmd.exe

by Anonymous Monk
on Nov 24, 2011 at 18:33 UTC ( #939933=note: print w/replies, xml ) Need Help??

in reply to Using Tab Completion on Windows in cmd.exe

Term::ReadKey ought to work, and anything using ReadKey(-1) for completion

  • Comment on Re: Using Tab Completion on Windows in cmd.exe

Replies are listed 'Best First'.
Re^2: Using Tab Completion on Windows in cmd.exe
by Anonymous Monk on Nov 24, 2011 at 19:22 UTC

    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

      Thanks a lot for your script. It works.

      So it means I have to reinvent the wheel and come up with my own readline function with tab completion support. I'll do that then, with the help of your script.

      Thanks again. :-)
        Sorry. Forgot to log in. It's my answer above.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://939933]
[1nickt]: Corion HPs? ugh. I was impressed with Lenovo's gaming laptops; if it weren't for the red backlighting and general flashiness of the aesthetic, I might have gone with that. But all that was until I discovered that the Dell Precision line is still around.
[1nickt]: stevieb I don;t doubt that there's a difference. BestBuy has "consumer" models only on display.
[ambrus]: 1nickt: for some reason, these days they call every computer "gaming", even ones that gamers wouldn't buy. I've bought a keyboard that was labelled "gamer", despite that it has hard springs and seems to be way better for typing than for gaming;
[1nickt]: I though the gamers like that because they bash the keys so hard.
[ambrus]: and I've seen motherboards with no fast expansion ports for a video card but built-in hardware RAID advertized as "gaming".
LanX has a shaming laptop
[ambrus]: 1nickt: my impression is that the gamers like the softer springs, because fast reaction time is more important to them then feedback from keypresses to recognize typos.

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (14)
As of 2017-03-27 13:41 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (320 votes). Check out past polls.