1 package Term::Complete;
6 @EXPORT = qw(Complete);
9 # @(#)complete.pl,v1.1 (me@anywhere.EBay.Sun.COM) 09/23/91
11 # Author: Wayne Thompson
14 # This routine provides word completion.
15 # (TAB) attempts word completion.
16 # (^D) prints completion list.
17 # (These may be changed by setting $Complete::complete, etc.)
20 # Bell when word completion fails.
23 # The tty driver is put into raw mode.
28 # $input = complete('prompt_string', \@completion_list);
30 # $input = complete('prompt_string', @completion_list);
42 if (ref $_[0] || $_[0] =~ /^\*/) {
43 @cmp_lst = sort @{$_[0]};
49 system('stty raw -echo');
51 print($prompt, $return);
52 while (($_ = getc(STDIN)) ne "\r") {
54 # (TAB) attempt completion
56 @match = grep(/^$return/, @cmp_lst);
57 $l = length($test = shift(@match));
58 unless ($#match < 0) {
59 foreach $cmp (@match) {
60 until (substr($cmp, 0, $l) eq substr($test, 0, $l)) {
66 print($test = substr($test, $r, $l - $r));
67 $r = length($return .= $test);
71 # (^D) completion list
72 $_ eq $complete && do {
73 print(join("\r\n", '', grep(/^$return/, @cmp_lst)), "\r\n");
88 ($_ eq $erase1 || $_ eq $erase2) && do {
107 system('stty -raw echo');