/[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 14 - (hide annotations)
Mon Jun 25 14:42:34 2007 UTC (16 years, 10 months ago) by dpavlin
File MIME type: text/plain
File size: 1486 byte(s)
set debug from command line
1 dpavlin 2 #!/usr/bin/perl
2    
3 dpavlin 8 use blib;
4 dpavlin 7 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 14 my $debug = shift @ARGV;
12    
13 dpavlin 5 if (0) {
14 dpavlin 2 $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 dpavlin 5 }
27 dpavlin 2
28     $sh->{"completion_function"} = \&completer;
29 dpavlin 5 $sh->prompt("Foo> ");
30 dpavlin 14 $sh->{debug} = $debug;
31 dpavlin 2
32 dpavlin 5 $sh->out("Welcome!");
33 dpavlin 2
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 dpavlin 5 @matches = grep(m/^\Q$curword\E/i, @WORDS);
53 dpavlin 2 }
54    
55     return @matches;
56     }

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26