| 1 | use strict; |
|---|
| 2 | use warnings; |
|---|
| 3 | |
|---|
| 4 | # Completers for client state |
|---|
| 5 | |
|---|
| 6 | package BarnOwl::Complete::Client; |
|---|
| 7 | |
|---|
| 8 | use BarnOwl::Completion::Util qw(complete_flags); |
|---|
| 9 | |
|---|
| 10 | my @all_colors = qw(default |
|---|
| 11 | black |
|---|
| 12 | blue |
|---|
| 13 | cyan |
|---|
| 14 | green |
|---|
| 15 | magenta |
|---|
| 16 | red |
|---|
| 17 | white |
|---|
| 18 | yellow); |
|---|
| 19 | |
|---|
| 20 | my %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 | |
|---|
| 42 | sub complete_command { return sort @BarnOwl::all_commands; } |
|---|
| 43 | sub complete_color { return @all_colors; } |
|---|
| 44 | sub complete_filter_name { return @{BarnOwl::all_filters()}; } |
|---|
| 45 | sub complete_variable {} # stub |
|---|
| 46 | |
|---|
| 47 | sub complete_filter_args { |
|---|
| 48 | my $ctx = shift; |
|---|
| 49 | my $arg = shift; |
|---|
| 50 | return if $arg; |
|---|
| 51 | return complete_filter_name(); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | sub complete_help { |
|---|
| 55 | my $ctx = shift; |
|---|
| 56 | return complete_flags($ctx, |
|---|
| 57 | [qw()], |
|---|
| 58 | { |
|---|
| 59 | }, |
|---|
| 60 | \&complete_command |
|---|
| 61 | ); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | sub complete_show { |
|---|
| 65 | my $ctx = shift; |
|---|
| 66 | if($ctx->word == 1) { |
|---|
| 67 | return keys %show; |
|---|
| 68 | } elsif ($ctx->word == 2) { |
|---|
| 69 | my $cmd = $show{$ctx->words->[1]}; |
|---|
| 70 | if($cmd) { |
|---|
| 71 | return $cmd->($ctx); |
|---|
| 72 | } |
|---|
| 73 | } |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | sub complete_filter { |
|---|
| 77 | my $ctx = shift; |
|---|
| 78 | return complete_flags($ctx, |
|---|
| 79 | [qw()], |
|---|
| 80 | { |
|---|
| 81 | "-c" => \&complete_color, |
|---|
| 82 | "-b" => \&complete_color, |
|---|
| 83 | }, |
|---|
| 84 | \&complete_filter_args |
|---|
| 85 | ); |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | sub complete_getvar { |
|---|
| 89 | my $ctx = shift; |
|---|
| 90 | return unless ($ctx->word == 1); |
|---|
| 91 | return complete_variable(); |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | sub complete_set { |
|---|
| 95 | my $ctx = shift; |
|---|
| 96 | return complete_flags($ctx, |
|---|
| 97 | [qw(-q)], |
|---|
| 98 | { |
|---|
| 99 | }, |
|---|
| 100 | \&complete_set_args |
|---|
| 101 | ); |
|---|
| 102 | } |
|---|
| 103 | sub complete_set_args { |
|---|
| 104 | my $ctx = shift; |
|---|
| 105 | my $arg = shift; |
|---|
| 106 | return if $arg; |
|---|
| 107 | return complete_variable(); |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | BarnOwl::Completion::register_completer(help => \&complete_help); |
|---|
| 111 | BarnOwl::Completion::register_completer(filter => \&complete_filter); |
|---|
| 112 | BarnOwl::Completion::register_completer(show => \&complete_show); |
|---|
| 113 | BarnOwl::Completion::register_completer(getvar => \&complete_getvar); |
|---|
| 114 | BarnOwl::Completion::register_completer(set => \&complete_set); |
|---|
| 115 | |
|---|
| 116 | 1; |
|---|