1 package Term::Complete;
6 @EXPORT = qw(Complete);
8 # @(#)complete.pl,v1.1 (me@anywhere.EBay.Sun.COM) 09/23/91
12 Term::Complete - Perl word completion module
16 $input = complete('prompt_string', \@completion_list);
17 $input = complete('prompt_string', @completion_list);
21 This routine provides word completion on the list of words in
22 the array (or array ref).
24 The tty driver is put into raw mode using the system command
25 C<stty raw -echo> and restored using C<stty -raw echo>.
27 The following command characters are defined:
33 Attempts word completion.
38 Prints completion list.
39 Defined by I<$Term::Complete::complete>.
43 Erases the current input.
44 Defined by I<$Term::Complete::kill>.
46 =item E<lt>delE<gt>, E<lt>bsE<gt>
49 Defined by I<$Term::Complete::erase1> and I<$Term::Complete::erase2>.
55 Bell sounds when word completion fails.
59 The completion charater E<lt>tabE<gt> cannot be changed.
75 my($prompt, @cmp_list, $return, @match, $l, $test, $cmp, $r);
78 if (ref $_[0] || $_[0] =~ /^\*/) {
79 @cmp_lst = sort @{$_[0]};
85 system('stty raw -echo');
87 print($prompt, $return);
88 while (($_ = getc(STDIN)) ne "\r") {
90 # (TAB) attempt completion
92 @match = grep(/^$return/, @cmp_lst);
93 $l = length($test = shift(@match));
94 unless ($#match < 0) {
95 foreach $cmp (@match) {
96 until (substr($cmp, 0, $l) eq substr($test, 0, $l)) {
102 print($test = substr($test, $r, $l - $r));
103 $r = length($return .= $test);
107 # (^D) completion list
108 $_ eq $complete && do {
109 print(join("\r\n", '', grep(/^$return/, @cmp_lst)), "\r\n");
124 # (DEL) || (BS) erase
125 ($_ eq $erase1 || $_ eq $erase2) && do {
144 system('stty -raw echo');