/[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

Annotation of /trunk/examples/demo.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7 - (hide annotations)
Mon Jun 25 08:45:29 2007 UTC (16 years, 11 months ago) by dpavlin
File MIME type: text/plain
File size: 1442 byte(s)
reorg directory structure so that examples are *not* installed together with module
1 dpavlin 2 #!/usr/bin/perl
2    
3 dpavlin 7 use lib 'lib';
4     use Term::Shelly;
5 dpavlin 2
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 dpavlin 5 if (0) {
12 dpavlin 2 $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 dpavlin 5 }
25 dpavlin 2
26     $sh->{"completion_function"} = \&completer;
27 dpavlin 5 $sh->prompt("Foo> ");
28 dpavlin 2
29 dpavlin 5 $sh->out("Welcome!");
30 dpavlin 2
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 dpavlin 5 @matches = grep(m/^\Q$curword\E/i, @WORDS);
50 dpavlin 2 }
51    
52     return @matches;
53     }

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26