Hello Bad_ptr and welcome to active participation to the monastery!

If i understand your needs, you can accomplish something very similar via Term::ReadLine and glob

Infact that module has autocompletion via TAB key. If you press TAB twice it display all possible valid combinations based on what you entered till now.

I see you use *.pl as pattern; if i understand your needs you can read the pattern enetered at the prompt and use glob to populate an array. You'll use this array to do the autocompletion.

That module is somehow tricky to use correctly and behaves differently depending on the OS.

Here you have a working solution:

use strict; use warnings; use Term::ReadLine; # I need this under windows: $ENV{TERM}=undef; my $term=Term::ReadLine->new("test"); print "Please enter a pattern:"; my $pattern = <STDIN>; chomp $pattern; my @files = glob($pattern); print "there are ",scalar @files," different possibilities.\n"; my $choosen = ''; $term->Attribs->{completion_function} = sub { my ($text, $line, $start) = @_; return grep { /^$text/i } @files ; }; while ( defined ( $_ = $term->readline( 'choose>') ) ) { # a blank bare line is entered? redo the loop next if /^$/; if ($_=~/.*$/){ chomp $_; $choosen = $_; last; } } print "You choosen [$choosen]\n";

If I call this program in the current directory I see (some space and comments added):

prompt>perl term-readline001.pl Please enter a pattern:*.jpg there are 23 different possibilities. choose> # TAB TAB display all pos +sibilities apod20100415.jpg cat.jpg city.jpg earth.jpg file.jpg file0.jpg file3.jpg file4.jpg file5.jpg file6.jpg file7.jpg file8.jpg flowers.jpg hacking-team-011509362-ff2f66c6-e452-4109-8bfb-6d4499c2bd5e.jpg kawasaki.jpg kid.jpg mandelbrot_set_color_zoom_by_zeno333-d4va5l8.jpg moon.jpg PICT0034.JPG romantic.jpg serfandolweb.jpg sunrise.jpg umbrella.jpg # if i press just ENTER nothing hap +pens choose> choose> choose> choose> choose>file # i press 'f' and after TAB: it dis +play all 'file*' files file.jpg file0.jpg file3.jpg file4.jpg file5.jpg file6.jpg file7.jpg +file8.jpg choose>file4.jpg # i enter '4' and TAB completes int +o the only one matching You choosen [file4.jpg ] # done! the program exit prompt>

I suggest you to read Re^3: about Term::ReadLine and it's imported function The Solution and the whole thread because Term::ReadLine is a bit dificult to manage.

HtH

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re: Terminal. Update text while user types. -- glob and Term::ReadLine solution by Discipulus
in thread Terminal. Update text while user types. by Bad_ptr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.