source: perl/lib/BarnOwl/Complete/Zephyr.pm @ 8f16dcd

release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 8f16dcd was 8f16dcd, checked in by Nelson Elhage <nelhage@mit.edu>, 12 years ago
Implement basic Zephyr completion based on previously-seen messages.
  • Property mode set to 100644
File size: 1.5 KB
Line 
1use strict;
2use warnings;
3
4package BarnOwl::Complete::Zephyr;
5
6use BarnOwl::Completion::Util qw(complete_flags);
7
8my %classes = ();
9my %realms = map {$_ => 1} qw(ATHENA.MIT.EDU ANDREW.CMU.EDU ZONE.MIT.EDU);
10my %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_sub {
33    my $ctx = shift;
34    return complete_flags($ctx,
35        [],
36        {
37            "-r" => \&complete_realm,
38        });
39}
40
41sub on_message {
42    my $m = shift;
43    return unless $m->type eq 'zephyr';
44    $classes{$m->class} = 1;
45    $realms{$m->realm} = 1;
46    $users{BarnOwl::Message::Zephyr::strip_realm($m->sender)} = 1;
47}
48
49BarnOwl::Completion::register_completer(zwrite    => \&complete_zwrite);
50BarnOwl::Completion::register_completer(zcrypt    => \&complete_zwrite);
51
52# TODO: Handle aliases transparently in the core completion code?
53BarnOwl::Completion::register_completer(sub       => \&complete_sub);
54BarnOwl::Completion::register_completer(subscribe => \&complete_sub);
55
56$BarnOwl::Hooks::newMessage->add("BarnOwl::Complete::Zephyr::on_message");
57
581;
Note: See TracBrowser for help on using the repository browser.