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

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26