Commit | Line | Data |
---|---|---|
0111154e Z |
1 | warn "Legacy library @{[(caller(0))[6]]} will be removed from the Perl core distribution in the next major release. Please install it from the CPAN distribution Perl4::CoreLibs. It is being used at @{[(caller)[1]]}, line @{[(caller)[2]]}.\n"; |
2 | ||
a687059c | 3 | ;# |
a6d71656 GS |
4 | # |
5 | # This library is no longer being maintained, and is included for backward | |
6 | # compatibility with Perl 4 programs which may require it. | |
1aaec297 S |
7 | # This legacy library is deprecated and will be removed in a future |
8 | # release of perl. | |
a6d71656 GS |
9 | # |
10 | # In particular, this should not be used as an example of modern Perl | |
11 | # programming techniques. | |
12 | # | |
13 | # Suggested alternative: Term::Complete | |
1aaec297 | 14 | |
55204971 | 15 | ;# @(#)complete.pl,v1.1 (me@anywhere.EBay.Sun.COM) 09/23/91 |
a687059c LW |
16 | ;# |
17 | ;# Author: Wayne Thompson | |
18 | ;# | |
19 | ;# Description: | |
20 | ;# This routine provides word completion. | |
21 | ;# (TAB) attempts word completion. | |
22 | ;# (^D) prints completion list. | |
55204971 | 23 | ;# (These may be changed by setting $Complete'complete, etc.) |
a687059c LW |
24 | ;# |
25 | ;# Diagnostics: | |
26 | ;# Bell when word completion fails. | |
27 | ;# | |
28 | ;# Dependencies: | |
29 | ;# The tty driver is put into raw mode. | |
30 | ;# | |
31 | ;# Bugs: | |
a687059c LW |
32 | ;# |
33 | ;# Usage: | |
55204971 LW |
34 | ;# $input = &Complete('prompt_string', *completion_list); |
35 | ;# or | |
36 | ;# $input = &Complete('prompt_string', @completion_list); | |
a687059c LW |
37 | ;# |
38 | ||
7e1cf235 LW |
39 | CONFIG: { |
40 | package Complete; | |
41 | ||
55204971 LW |
42 | $complete = "\004"; |
43 | $kill = "\025"; | |
44 | $erase1 = "\177"; | |
45 | $erase2 = "\010"; | |
7e1cf235 LW |
46 | } |
47 | ||
a687059c | 48 | sub Complete { |
7e1cf235 LW |
49 | package Complete; |
50 | ||
55497cff | 51 | local($prompt, @cmp_list, $return, @match, $l, $test, $cmp, $r); |
55204971 LW |
52 | if ($_[1] =~ /^StB\0/) { |
53 | ($prompt, *_) = @_; | |
a687059c | 54 | } |
55204971 LW |
55 | else { |
56 | $prompt = shift(@_); | |
57 | } | |
58 | @cmp_lst = sort(@_); | |
59 | ||
60 | system('stty raw -echo'); | |
61 | LOOP: { | |
62 | print($prompt, $return); | |
63 | while (($_ = getc(STDIN)) ne "\r") { | |
64 | CASE: { | |
65 | # (TAB) attempt completion | |
66 | $_ eq "\t" && do { | |
67 | @match = grep(/^$return/, @cmp_lst); | |
68 | $l = length($test = shift(@match)); | |
69 | unless ($#match < 0) { | |
70 | foreach $cmp (@match) { | |
71 | until (substr($cmp, 0, $l) eq substr($test, 0, $l)) { | |
72 | $l--; | |
73 | } | |
74 | } | |
75 | print("\a"); | |
76 | } | |
77 | print($test = substr($test, $r, $l - $r)); | |
78 | $r = length($return .= $test); | |
79 | last CASE; | |
80 | }; | |
81 | ||
82 | # (^D) completion list | |
83 | $_ eq $complete && do { | |
84 | print(join("\r\n", '', grep(/^$return/, @cmp_lst)), "\r\n"); | |
85 | redo LOOP; | |
86 | }; | |
87 | ||
88 | # (^U) kill | |
89 | $_ eq $kill && do { | |
90 | if ($r) { | |
40da2db3 JH |
91 | undef $r; |
92 | undef $return; | |
55204971 LW |
93 | print("\r\n"); |
94 | redo LOOP; | |
95 | } | |
96 | last CASE; | |
97 | }; | |
98 | ||
99 | # (DEL) || (BS) erase | |
100 | ($_ eq $erase1 || $_ eq $erase2) && do { | |
101 | if($r) { | |
102 | print("\b \b"); | |
103 | chop($return); | |
104 | $r--; | |
105 | } | |
106 | last CASE; | |
107 | }; | |
108 | ||
109 | # printable char | |
110 | ord >= 32 && do { | |
111 | $return .= $_; | |
112 | $r++; | |
113 | print; | |
114 | last CASE; | |
115 | }; | |
116 | } | |
117 | } | |
118 | } | |
119 | system('stty -raw echo'); | |
120 | print("\n"); | |
a687059c LW |
121 | $return; |
122 | } | |
123 | ||
124 | 1; |