/[Term-Shelly]/trunk/foo.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/foo.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5 - (show annotations)
Mon Jun 25 08:32:23 2007 UTC (16 years, 11 months ago) by dpavlin
File MIME type: text/plain
File size: 1421 byte(s)
update all changes to (never released) verison 0.02 from
http://www.semicomplete.com/svnweb/trunk/Term-Shelly/?pathrev=1301
1 #!/usr/bin/perl
2
3 use Shelly;
4
5 my @COMMANDS = qw(help server login connect message disconnect hop);
6 my @WORDS = qw(hello how are you today fantasy rumble forward down fast);
7
8 my $sh = Term::Shelly->new();
9
10 if (0) {
11 $sh->out(
12 "This is a demo of Term::Shelly. It is designed to show you some of the
13 features of it. For this demo there is only a short number of features
14 available, more will appear later. You can do basic line editing (arrows move
15 around, backspace, ^W, tab completion, ^U, etc)","","The following commands can
16 be tab completed:
17 " . join(" ", @COMMANDS) . "
18 However, no commands actually do anything, this is jus tto demo the tab
19 completion system. The following words can be tab completed:
20 " . join(" ", @WORDS)."
21 Commands must start with a / (forward slash) and be at the beginning of
22 the line.");
23 }
24
25 $sh->{"completion_function"} = \&completer;
26 $sh->prompt("Foo> ");
27
28 $sh->out("Welcome!");
29
30 while (1) {
31 $sh->do_one_loop();
32 }
33
34 sub completer {
35 my ($line, $bword, $pos, $curword) = @_;
36
37 my @matches;
38
39 # Context-sensitive completion.
40 #
41 # Only complete commands if our current word begins on the 0th column
42 # and starts with a / (slash)
43 if (($bword == 0) && (substr($line,$bword,1) eq '/')) {
44 # We want to complete a command...
45 $word = substr($curword,1);
46 @matches = map { "/$_" } grep(m/^\Q$word\E/i, @COMMANDS);
47 } else {
48 @matches = grep(m/^\Q$curword\E/i, @WORDS);
49 }
50
51 return @matches;
52 }

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26