source: perl/lib/BarnOwl/Complete/Client.pm @ 7940ac2

release-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 7940ac2 was 7940ac2, checked in by David Benjamin <davidben@mit.edu>, 15 years ago
Simplify complete_help and make correct Don't use complete_flags for complete_help. It doesn't need it. Signed-off-by: David Benjamin <davidben@mit.edu>
  • Property mode set to 100644
File size: 2.5 KB
Line 
1use strict;
2use warnings;
3
4# Completers for client state
5
6package BarnOwl::Complete::Client;
7
8use BarnOwl::Completion::Util qw(complete_flags);
9
10my @all_colors = qw(default
11                    black
12                    blue
13                    cyan
14                    green
15                    magenta
16                    red
17                    white
18                    yellow);
19
20my %show = (
21    information => undef,
22    colors      => undef,
23    commands    => undef,
24    command     => \&complete_command,
25    filters     => undef,
26    filter      => \&complete_filter_name,
27    license     => undef,
28    quickstart  => undef,
29    startup     => undef,
30    status      => undef,
31    styles      => undef,
32    subscriptions       => undef,
33    subs        => undef,
34    terminal    => undef,
35    variables   => undef,
36    variable    => \&complete_variable,
37    version     => undef,
38    view        => undef,
39    zpunts      => undef,
40   );
41
42sub complete_command { return sort @BarnOwl::all_commands; }
43sub complete_color { return @all_colors; }
44sub complete_filter_name { return @{BarnOwl::all_filters()}; }
45sub complete_variable {}        # stub
46
47sub complete_filter_args {
48    my $ctx = shift;
49    my $arg = shift;
50    return if $arg;
51    return complete_filter_name();
52}
53
54sub complete_help {
55    my $ctx = shift;
56    if($ctx->word == 1) {
57        return complete_command();
58    }
59}
60
61sub complete_show {
62    my $ctx = shift;
63    if($ctx->word == 1) {
64        return keys %show;
65    } elsif ($ctx->word == 2) {
66        my $cmd = $show{$ctx->words->[1]};
67        if($cmd) {
68            return $cmd->($ctx);
69        }
70    }
71}
72
73sub complete_filter {
74    my $ctx = shift;
75    return complete_flags($ctx,
76        [qw()],
77        {
78           "-c" => \&complete_color,
79           "-b" => \&complete_color,
80        },
81         \&complete_filter_args
82        );
83}
84
85sub complete_getvar {
86    my $ctx = shift;
87    return unless ($ctx->word == 1);
88    return complete_variable();
89}
90
91sub complete_set {
92    my $ctx = shift;
93    return complete_flags($ctx,
94        [qw(-q)],
95        {
96        },
97         \&complete_set_args
98        );
99}
100sub complete_set_args {
101    my $ctx = shift;
102    my $arg = shift;
103    return if $arg;
104    return complete_variable();
105}
106
107BarnOwl::Completion::register_completer(help    => \&complete_help);
108BarnOwl::Completion::register_completer(filter  => \&complete_filter);
109BarnOwl::Completion::register_completer(show    => \&complete_show);
110BarnOwl::Completion::register_completer(getvar  => \&complete_getvar);
111BarnOwl::Completion::register_completer(set     => \&complete_set);
112
1131;
Note: See TracBrowser for help on using the repository browser.