source: perl/lib/BarnOwl/Complete/Client.pm @ dcc3f80

release-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since dcc3f80 was a3a9eb7, checked in by David Benjamin <davidben@mit.edu>, 15 years ago
Move complete_filter_{expr,name} to own module Moved to Complete::Filter to aviod cluttering up Complete::Client with private functions for complete_filter_expr. Signed-off-by: David Benjamin <davidben@mit.edu>
  • Property mode set to 100644
File size: 3.8 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    filters     => undef,
27    filter      => \&complete_filter_name,
28    license     => undef,
29    quickstart  => undef,
30    startup     => undef,
31    status      => undef,
32    styles      => undef,
33    subscriptions       => undef,
34    subs        => undef,
35    terminal    => undef,
36    variables   => undef,
37    variable    => \&complete_variable,
38    version     => undef,
39    view        => undef,
40    zpunts      => undef,
41   );
42
43sub complete_command { return sort @BarnOwl::all_commands; }
44sub complete_color { return @all_colors; }
45sub complete_variable    { return @{BarnOwl::all_variables()}; }
46sub complete_style       { return @{BarnOwl::all_styles()}; }
47
48sub complete_help {
49    my $ctx = shift;
50    if($ctx->word == 1) {
51        return complete_command();
52    }
53}
54
55sub complete_show {
56    my $ctx = shift;
57    if($ctx->word == 1) {
58        return keys %show;
59    } elsif ($ctx->word == 2) {
60        my $cmd = $show{$ctx->words->[1]};
61        if($cmd) {
62            return $cmd->($ctx);
63        }
64    }
65}
66
67sub complete_filter {
68    my $ctx = shift;
69    # Syntax: filter FILTERNAME FLAGS EXPR
70
71    # FILTERNAME
72    return complete_filter_name() if $ctx->word == 1;
73
74    # FLAGS
75    $ctx = $ctx->shift_words(1); # complete_flags starts at the second word
76    return complete_flags($ctx,
77        [qw()],
78        {
79           "-c" => \&complete_color,
80           "-b" => \&complete_color,
81        },
82        # EXPR
83        sub {
84            my $ctx = shift;
85            my $arg = shift;
86
87            # We pass stop_at_nonflag, so we can rewind to the start
88            my $idx = $ctx->word - $arg;
89            $ctx = $ctx->shift_words($idx);
90            return complete_filter_expr($ctx);
91        },
92        stop_at_nonflag => 1
93        );
94}
95
96sub complete_view {
97    my $ctx = shift;
98    if ($ctx->word == 1) {
99        return ("--home", "-d", "-r", "-s", complete_filter_name());
100    }
101    if ($ctx->words->[1] eq "--home") {
102        return;
103    }
104    if ($ctx->words->[1] eq "-d") {
105        $ctx = $ctx->shift_words(2);
106        return complete_filter_expr($ctx);
107    }
108    if ($ctx->words->[1] eq "-s") {
109        return complete_style();
110    }
111    return;
112}
113
114sub complete_getvar {
115    my $ctx = shift;
116    return unless ($ctx->word == 1);
117    return complete_variable();
118}
119
120sub complete_set {
121    my $ctx = shift;
122    return complete_flags($ctx,
123        [qw(-q)],
124        {
125        },
126         \&complete_set_args
127        );
128}
129sub complete_set_args {
130    my $ctx = shift;
131    my $arg = shift;
132    return if $arg;
133    return complete_variable();
134}
135
136sub complete_startup {
137    my $ctx = shift;
138    my $new_ctx = $ctx->shift_words(1);
139    return BarnOwl::Completion::get_completions($new_ctx);
140}
141
142BarnOwl::Completion::register_completer(help    => \&complete_help);
143BarnOwl::Completion::register_completer(filter  => \&complete_filter);
144BarnOwl::Completion::register_completer(view    => \&complete_view);
145BarnOwl::Completion::register_completer(show    => \&complete_show);
146BarnOwl::Completion::register_completer(getvar  => \&complete_getvar);
147BarnOwl::Completion::register_completer(set     => \&complete_set);
148BarnOwl::Completion::register_completer(unset   => \&complete_set);
149BarnOwl::Completion::register_completer(startup => \&complete_startup);
150
1511;
Note: See TracBrowser for help on using the repository browser.