source: perl/lib/BarnOwl/Complete/Zephyr.pm @ e6e7842

release-1.9
Last change on this file since e6e7842 was e6e7842, checked in by David Benjamin <davidben@mit.edu>, 9 years ago
Complete viewperson and vp as viewuser and vu
  • Property mode set to 100644
File size: 2.0 KB
Line 
1use strict;
2use warnings;
3
4package BarnOwl::Complete::Zephyr;
5
6use BarnOwl::Completion::Util qw(complete_flags);
7
8our %classes = ();
9our %realms = map {$_ => 1} qw(ATHENA.MIT.EDU ANDREW.CMU.EDU ZONE.MIT.EDU);
10our %users = ();
11
12sub complete_class    { keys %classes }
13sub complete_instance { }
14sub complete_realm    { keys %realms }
15sub complete_opcode   { }
16sub complete_user     { keys %users; }
17
18sub complete_zwrite {
19    my $ctx = shift;
20    return complete_flags($ctx,
21        [qw(-n -C -m)],
22        {
23            "-c" => \&complete_class,
24            "-i" => \&complete_instance,
25            "-r" => \&complete_realm,
26            "-O" => \&complete_opcode,
27        },
28        \&complete_user
29       );
30}
31
32sub complete_viewclass {
33    my $ctx = shift;
34    return unless $ctx->word == 1;
35    return complete_class();
36}
37
38sub complete_viewuser {
39    my $ctx = shift;
40    return unless $ctx->word == 1;
41    return complete_user();
42}
43
44sub complete_unsub {
45    my $ctx = shift;
46    return unless $ctx->word == 1;
47    return complete_class();
48}
49
50sub on_message {
51    my $m = shift;
52    return unless $m->type eq 'zephyr';
53    $classes{lc $m->class} = 1;
54    $realms{lc $m->realm} = 1;
55    $users{lc BarnOwl::Message::Zephyr::strip_realm($m->sender)} = 1;
56}
57
58BarnOwl::Completion::register_completer(zwrite    => \&complete_zwrite);
59BarnOwl::Completion::register_completer(zcrypt    => \&complete_zwrite);
60
61# Aliases should really be taken care of by the core completion code.
62BarnOwl::Completion::register_completer(viewclass => \&complete_viewclass);
63BarnOwl::Completion::register_completer(vc        => \&complete_viewclass);
64BarnOwl::Completion::register_completer(viewuser  => \&complete_viewuser);
65BarnOwl::Completion::register_completer(vu        => \&complete_viewuser);
66BarnOwl::Completion::register_completer(viewperson => \&complete_viewuser);
67BarnOwl::Completion::register_completer(vp        => \&complete_viewuser);
68
69BarnOwl::Completion::register_completer(unsub     => \&complete_unsub);
70
71$BarnOwl::Hooks::newMessage->add("BarnOwl::Complete::Zephyr::on_message");
72
731;
Note: See TracBrowser for help on using the repository browser.