Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I am not clear how to get the uncompleted command from the console.

The following minimal shell might help. You get the current word as the first parameter to the complete() function:

use Term::ReadLine; my $term = Term::ReadLine->new('console_app'); my $attr = $term->Attribs; $attr->{attempted_completion_function} = \&complete; our @keywords; chop and push @keywords, split while <DATA>; while (1) { my $line = $term->readline("perl >"); eval $line; warn $@ if $@; }; sub complete { my ($text, $line, $start, $end) = @_; # See if current word matches a package symbol my @matches = grep { /^\Q$text/ } keys %::; # current package if (@matches) { return @matches; } # nope? then check for builtins. return $term->completion_matches($text,\&keyword); }; { my $i; sub keyword { my ($text, $state) = @_; return unless $text; if($state) { $i++; } else { # first call $i = 0; } for (; $i<=$#keywords; $i++) { return $keywords[$i] if $keywords[$i] =~ /^\Q$text/; }; return undef; } }; # builtins (extracted from perlfunc) __DATA__ chomp chop chr crypt hex index lc lcfirst length oct ord pack reverse rindex sprintf substr uc ucfirst pos quotemeta split study abs atan2 cos exp hex int log oct rand sin sqrt srand pop push shift splice unshift grep join map reverse sort unpack delete each exists keys values binmode close closedir dbmclose dbmopen die eof fileno flock format getc print printf read readdir rewinddir seek seekdir select syscall sysread sysseek syswrite tell telldir truncate warn write pack read syscall sysread syswrite unpack vec chdir chmod chown chroot fcntl glob ioctl link lstat mkdir open opendir readlink rename rmdir stat symlink sysopen umask unlink utime caller continue die do dump eval exit goto last next redo return sub wantarray caller import local my our package use defined dump eval formline local my our reset scalar undef wantarray alarm exec fork getpgrp getppid getpriority kill pipe setpgrp setpriority sleep system times wait waitpid do import no package require use bless dbmclose dbmopen package ref tie tied untie use accept bind connect getpeername getsockname listen recv send setsockopt shutdown socket socketpair msgctl msgget msgrcv msgsnd semctl semget semop shmctl shmget shmread shmwrite endgrent endhostent endnetent endpwent getgrent getgrgid getgrnam getlogin getpwent getpwnam setgrent setpwent endprotoent endservent gethostbyaddr gethostbyname gethostent getnetbyaddr getnetbyname getnetent getprotobynumber getprotoent getservbyname getservbyport getservent sethostent setnetent setservent gmtime localtime time times abs bless chomp chr exists formline glob import lc lcfirst map my no our prototype qx qw readline readpipe ref sysopen tie tied uc ucfirst untie use sub


_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

In reply to Re: Autocomplete in perl console application by shmem
in thread Autocomplete in perl console application by raghrao

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2024-06-20 00:24 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.