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:
32 Attempts word completion.
37 Prints completion list.
38 Defined by I<$Term::Complete::complete>.
42 Erases the current input.
43 Defined by I<$Term::Complete::kill>.
48 Defined by I<$Term::Complete::erase1> and I<$Term::Complete::erase2>.
54 Bell sounds when word completion fails.
58 The completion charater <tab> cannot be changed.
75 if (ref $_[0] || $_[0] =~ /^\*/) {
76 @cmp_lst = sort @{$_[0]};
82 system('stty raw -echo');
84 print($prompt, $return);
85 while (($_ = getc(STDIN)) ne "\r") {
87 # (TAB) attempt completion
89 @match = grep(/^$return/, @cmp_lst);
90 $l = length($test = shift(@match));
91 unless ($#match < 0) {
92 foreach $cmp (@match) {
93 until (substr($cmp, 0, $l) eq substr($test, 0, $l)) {
99 print($test = substr($test, $r, $l - $r));
100 $r = length($return .= $test);
104 # (^D) completion list
105 $_ eq $complete && do {
106 print(join("\r\n", '', grep(/^$return/, @cmp_lst)), "\r\n");
120 # (DEL) || (BS) erase
121 ($_ eq $erase1 || $_ eq $erase2) && do {
140 system('stty -raw echo');