source: perl/lib/BarnOwl/Complete/Client.pm @ 02a72bf

release-1.10release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 02a72bf was 02a72bf, checked in by David Benjamin <davidben@mit.edu>, 14 years ago
Further complete the show command Add subcommands keymap(s) and errors. Also, complete from the list of keymaps. Signed-off-by: David Benjamin <davidben@mit.edu>
  • Property mode set to 100644
File size: 3.9 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);
9use BarnOwl::Complete::Filter qw(complete_filter_name complete_filter_expr);
10
11my @all_colors = qw(default
12                    black
13                    blue
14                    cyan
15                    green
16                    magenta
17                    red
18                    white
19                    yellow);
20
21my %show = (
22    information => undef,
23    colors      => undef,
24    commands    => undef,
25    command     => \&complete_command,
26    errors      => undef,
27    filters     => undef,
28    filter      => \&complete_filter_name,
29    license     => undef,
30    keymaps     => undef,
31    keymap      => \&complete_keymap,
32    quickstart  => undef,
33    startup     => undef,
34    status      => undef,
35    styles      => undef,
36    subscriptions       => undef,
37    subs        => undef,
38    terminal    => undef,
39    variables   => undef,
40    variable    => \&complete_variable,
41    version     => undef,
42    view        => undef,
43    zpunts      => undef,
44   );
45
46sub complete_command { return sort @BarnOwl::all_commands; }
47sub complete_color { return @all_colors; }
48sub complete_variable    { return @{BarnOwl::all_variables()}; }
49sub complete_style       { return @{BarnOwl::all_styles()}; }
50sub complete_keymap      { return @{BarnOwl::all_keymaps()}; }
51
52sub complete_help {
53    my $ctx = shift;
54    if($ctx->word == 1) {
55        return complete_command();
56    }
57}
58
59sub complete_show {
60    my $ctx = shift;
61    if($ctx->word == 1) {
62        return keys %show;
63    } elsif ($ctx->word == 2) {
64        my $cmd = $show{$ctx->words->[1]};
65        if($cmd) {
66            return $cmd->($ctx);
67        }
68    }
69}
70
71sub complete_filter {
72    my $ctx = shift;
73    # Syntax: filter FILTERNAME FLAGS EXPR
74
75    # FILTERNAME
76    return complete_filter_name() if $ctx->word == 1;
77
78    # FLAGS
79    $ctx = $ctx->shift_words(1); # complete_flags starts at the second word
80    return complete_flags($ctx,
81        [qw()],
82        {
83           "-c" => \&complete_color,
84           "-b" => \&complete_color,
85        },
86        # EXPR
87        sub {
88            my $ctx = shift;
89            my $arg = shift;
90
91            # We pass stop_at_nonflag, so we can rewind to the start
92            my $idx = $ctx->word - $arg;
93            $ctx = $ctx->shift_words($idx);
94            return complete_filter_expr($ctx);
95        },
96        stop_at_nonflag => 1
97        );
98}
99
100sub complete_view {
101    my $ctx = shift;
102    if ($ctx->word == 1) {
103        return ("--home", "-d", "-r", "-s", complete_filter_name());
104    }
105    if ($ctx->words->[1] eq "--home") {
106        return;
107    }
108    if ($ctx->words->[1] eq "-d") {
109        $ctx = $ctx->shift_words(2);
110        return complete_filter_expr($ctx);
111    }
112    if ($ctx->words->[1] eq "-s") {
113        return complete_style();
114    }
115    return;
116}
117
118sub complete_getvar {
119    my $ctx = shift;
120    return unless ($ctx->word == 1);
121    return complete_variable();
122}
123
124sub complete_set {
125    my $ctx = shift;
126    return complete_flags($ctx,
127        [qw(-q)],
128        {
129        },
130         \&complete_set_args
131        );
132}
133sub complete_set_args {
134    my $ctx = shift;
135    my $arg = shift;
136    return if $arg;
137    return complete_variable();
138}
139
140sub complete_startup {
141    my $ctx = shift;
142    my $new_ctx = $ctx->shift_words(1);
143    return BarnOwl::Completion::get_completions($new_ctx);
144}
145
146BarnOwl::Completion::register_completer(help    => \&complete_help);
147BarnOwl::Completion::register_completer(filter  => \&complete_filter);
148BarnOwl::Completion::register_completer(view    => \&complete_view);
149BarnOwl::Completion::register_completer(show    => \&complete_show);
150BarnOwl::Completion::register_completer(getvar  => \&complete_getvar);
151BarnOwl::Completion::register_completer(set     => \&complete_set);
152BarnOwl::Completion::register_completer(unset   => \&complete_set);
153BarnOwl::Completion::register_completer(startup => \&complete_startup);
154
1551;
Note: See TracBrowser for help on using the repository browser.