/[Term-Shelly]/trunk/examples/demo.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/examples/demo.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26