source: examples/owlconf.erik @ f1e629d

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since f1e629d was f1e629d, checked in by Erik Nygren <nygren@mit.edu>, 21 years ago
New API for perl message formatting functions. Legacy variables are still supported for owl::format_msg and owl::receive_msg, but these functions are now also passed an owl::Message object which contains methods for accessing the contents of the message. See perlwrap.pm (and docs TBD) for the available methods. *** WARNING: The exact API for owl::Message has *** not yet stabilized. Added "style" command for creating new styles. Usage: style <name> perl <function_name> Added support for "show styles". Changed global style table from list to dictionary. Changed AIM password prompt from "Password:" to "AIM Password:". Messages are reformatted after a window resize to allow styles to take into account the width of the window. When perl throws an error, the message is put in the msgwin if possible. Added perl functions for: owl::getcurmsg() -- returns an owl::Message object for the active message in the current view. owl::getnumcols() -- returns the column width of the window owl::zephyr_getrealm() -- returns the zephyr realm owl::zephyr_getsender() -- returns the zephyr sender Made owl::COMMAND("foo"); be syntactic sugar for owl::command("COMMAND foo"); *** Is this a good or bad idea? *** This feature may be taken out before release. Added perlwrap.pm to contain perl code to be compiled into the binary. This is transformed into perlwrap.c by encapsulate.pl. Renamed readconfig.c to perlconfig.c and changed variables accordingly. Minor bugfixes in cmd.c and commands.c
  • Property mode set to 100644
File size: 12.9 KB
Line 
1### The owlconf config file   -*- perl -*- 
2###  $Id$
3###
4### !!!!!WARNING!!!!! !!!!!WARNING!!!!! !!!!!WARNING!!!!! !!!!!WARNING!!!!!
5### This is an example file intended to demonstrate how to use
6### various features of owl.  Some of the key bindings, in particular,
7### are more for examples than things you may actually want to use.
8### Make sure to read through it first and understand it before just using it.
9### Don't blame me if anything in here ends up vaporizing your dog.
10### !!!!!WARNING!!!!! !!!!!WARNING!!!!! !!!!!WARNING!!!!! !!!!!WARNING!!!!!
11###
12###
13### This file is interpreted by the perl interpreter.
14### If you wish to execute an owl command use the
15### function owl::command().  i.e.
16###
17###      owl::command("set zsigproc /mit/kretch/bin/getzsig");
18###
19### will set the owl variable zsigproc.  Subroutines created with
20### the names below will be executed at the specified times:
21###
22###     subroutine name    properties
23###     ---------------    ----------
24###     owl::startup()     run when owl first starts
25###     owl::shutdown()    run when owl exits
26###     owl::format_msg()  formats messages that are passed to it
27###     owl::receive_msg() run when a message is received, and after
28###                        it has been added to the message list
29###
30### The format_msg and receive_msg functions are passed owl::Message objects.
31### The message attributes may be dereferenced with $m->attribute
32###
33###   
34
35# tokens for sepbar are:
36#    .username = ping
37#    >username = login
38#    <username = logout
39#    :username = personal message
40#    M         = mail received
41my @sepbartokens = ();
42
43# Map for mail messages from msg id to pop msg id
44my %mail_id_map = ();
45
46# (originally from jdaniel)
47sub mail_add_message ($) {
48    my ($m) = @_;
49    my $from = `from -t`;
50    # example value:
51    # You have 188 messages (667593 bytes) on PO11.MIT.EDU.
52    my ($msg_num) = $from =~ m/(\d+)/;
53    $mail_id_map{$m->id} = $msg_num;
54}
55
56
57sub mail_pop_curmsg () {
58    my $m = owl::getcurmsg();
59    if (!$m->is_mail || !defined $mail_id_map{$m->id}) {
60        &owl::command("pop-message");
61    } else {
62        &owl::command(sprintf 'pexec pop -request c -request "retr %d" -request q',
63                      $mail_id_map{$m->id});
64    }
65}
66
67sub zlocatesender {
68    my $m = owl::getcurmsg();
69    if ($m->{"type"} eq "zephyr") {
70        my $sender = $m->{"sender"};
71        owl::command("zlocate $sender");
72    }
73}
74
75# adds a sepbartoken and also updates the appendtosepbar variable
76sub sepbartokens_add {
77    my ($token) = @_;
78    $token =~ s/"//g;  # "
79    unshift @sepbartokens, $token;
80    pop @sepbartokens if (@sepbartokens > 80);
81    sepbartokens_set();
82}
83
84# trims a sepbartoken from the list also updates the appendtosepbar variable
85sub sepbartokens_trim {
86    my ($token) = @_;
87    @sepbartokens = map { if ($_ ne $token) { $_; } else { (); } } @sepbartokens;
88    sepbartokens_set();
89}
90
91my $loopctr=0;
92
93# trims a sepbartoken from the list also updates the appendtosepbar variable
94sub sepbartokens_set {
95    owl::command(sprintf "set -q appendtosepbar \"%s %s %s\"", (scalar localtime), (join " ", @sepbartokens));
96}
97
98my $restoreview = undef;
99sub swapview {
100    my $curview = owl::command("getview");
101    if ($restoreview) {
102        owl::command("view $restoreview");
103        $restoreview = undef;
104    } else {
105        $restoreview = $curview;
106        owl::command("smartnarrow");
107    }
108}
109
110my $lastcolored = undef;
111sub colorthread {
112    if ($lastcolored) {
113        owl::command("filter $lastcolored -c default");
114    }
115    my $smartfilt = owl::command("smartfilter");
116    if (!$smartfilt or $smartfilt eq $lastcolored) {
117        owl::command("filter $lastcolored -c default");
118        $lastcolored = undef;
119    } else {
120        owl::command("filter $smartfilt -c green");
121        $lastcolored = $smartfilt;
122    }
123}
124
125# Load in things which don't belong in an owlconf
126# that people might use as an example...
127sub personal_startup {
128    my $personalconf = $ENV{"HOME"}."/.owl/personalconf";
129    if (-f $personalconf) {
130        my $b = "";
131        open INB, $personalconf;
132        for (<INB>) { $b .= $_; }
133        close INB;
134        eval $b;
135    }
136}
137
138sub owl::startup {
139    owl::command("set -q logging on");
140    owl::command("set -q logpath ~/.zlog/owl/personal");
141    owl::command("set -q classlogpath ~/.zlog/owl/class");
142    owl::command("set -q logging on");
143    owl::command("set -q startuplogin off");
144    owl::command("set -q shutdownlogout off");
145    #owl::command("set personalbell on");
146    owl::command("set -q _burningears on");
147    owl::command("set -q rxping on");
148    owl::command("set -q typewinsize 5");
149    if ($ENV{"DISPLAY"} eq ":0.0") {
150      owl::command("set -q webbrowser galeon"); 
151    }
152    owl::command("filter me recipient %me% or ( sender %me% and class message and instance personal ) or class mail or type aim");
153    owl::command("filter owl instance ^owl.*");
154
155    owl::command(q(alias finger pperl $x=owl::getcurmsg()->hostname; `finger \@$x`;));
156    owl::command("bindkey recv f command finger");
157
158    owl::command("alias z zwrite");
159    owl::command("alias zw zwrite");
160    owl::command("alias v view");
161
162    owl::command("alias popmail perl mail_pop_curmsg();");
163
164    # toggle between a view and a smartnarrow with TAB
165    owl::command("alias swapview perl swapview();");
166    owl::command("bindkey recv C-i command swapview");
167
168    # color the current thread
169    owl::command("alias colorthread perl colorthread();");
170    owl::command("bindkey recv M-c command colorthread");
171
172    # zlocate current sender
173    owl::command("bindkey recv L command perl zlocatesender();");
174
175    # Declare styles
176    &owl::command("style vt     perl format_msg_vt");
177    &owl::command("style brief  perl format_msg_brief");
178    &owl::command("style custom perl format_msg_custom");
179    &owl::command("style debug  perl format_msg_debug");
180    &owl::command("set -q default_style custom");
181
182    # Change to different view styles
183    owl::command("bindkey recv \"C-s v\" command view -s vt");
184    owl::command("bindkey recv \"C-s c\" command view -s custom");
185    owl::command("bindkey recv \"C-s b\" command view -s brief");
186    owl::command("bindkey recv \"C-s d\" command view -s debug");
187    owl::command("bindkey recv \"C-s o\" command view -s standard");
188
189    # For fast-reading of zephyrs
190    owl::command("bindkey recv M-k command ( smartnarrow ; delete view )");
191    owl::command("bindkey recv M-l command ( expunge ; view all )");
192    owl::command("bindkey recv M-K command ( smartnarrow ; delete view ; expunge ; view all )");
193
194    # Support for scroll mice
195    &owl::command("bindkey recv \"M-[ A\" command recv:prev");
196    &owl::command("bindkey recv \"M-[ B\" command recv:next");
197
198    # This overrides the default "M" keybinding
199    owl::command("bindkey recv M command popmail");
200
201    sepbartokens_add("...");
202
203    personal_startup();
204}
205
206sub owl::shutdown {
207#    not doing anything at the moment...
208}
209
210
211# run when a message is received, and after
212# it has been added to the message list.
213sub owl::receive_msg {
214    my ($m) = @_;
215    my ($out, $tmp);
216
217    if ($m->is_admin && !$m->is_outgoing) {
218        $m->delete();
219        return 1;
220    }
221
222    return 0 if (!$m->is_zephyr && !$m->is_aim);
223
224    my $sender = $m->pretty_sender;
225
226    if ($m->is_ping) {
227        sepbartokens_add(".$sender");
228        $m->delete();
229    } elsif ($m->is_loginout) {
230        $m->delete();
231        if ($m->is_login) {
232            sepbartokens_add(">$sender");
233            sepbartokens_trim("<$sender");
234        } elsif ($m->is_logout) {
235            sepbartokens_add("<$sender");
236            sepbartokens_trim(">$sender");
237        } 
238    } elsif ($m->is_mail) {
239        mail_add_message($m);
240        $m->delete();
241        sepbartokens_add("M");
242    }
243
244    if ($m->is_personal) {
245        sepbartokens_trim(".$sender");
246        sepbartokens_add(":$sender");
247    }
248
249    return 1;
250}
251
252sub indent4 {
253    my ($b) = @_;
254    $b=~s/^/    /g;
255    $b=~s/\n/\n    /g;   
256    return $b;
257}
258
259# run to format a message
260sub format_msg_custom {
261    my ($m) = @_;
262    my ($out, $tmp);
263
264    if ($m->is_admin) {
265        $out = "\@bold([owl admin]) ".$m->header."\n";
266        $out.=indent4($m->body);
267        return $out."\n";
268    }
269
270    my $sender=$m->pretty_sender;
271
272    if (($m->is_aim or $m->is_zephyr) && $m->is_loginout) {
273
274        if ($m->is_login) {
275            $out="\@bold(LOGIN)";
276        } elsif ($m->is_logout) {
277            $out="\@bold(LOGOUT)";
278        } else {
279            $out="\@bold(UNKNOWN)";
280        }
281        $out.=" for \@bold($sender) on ".$m->type;
282        if ($m->is_zephyr) {
283            $out.=" at ".($m->login_host)." on ".($m->login_tty)."\n";
284        }
285        return($out);
286    }
287
288    if (!$m->is_zephyr && !$m->is_aim) { 
289        return "Unknown message type: ".$m->type."\n";
290    }
291
292    if ($m->is_outgoing) {
293        my $target = $m->recipient;
294        if ($m->is_zephyr) {
295            $target = $m->zwriteline;
296            $target =~ s/^zwrite //;
297        }
298        $out = sprintf "\@bold([outgoing %s to %s]) / %s\n", $m->type, $target, $m->time;
299        $out.=indent4($m->body);
300        return $out;
301    }
302
303    if ($m->is_zephyr && $m->is_ping) {
304        return("\@bold(PING) from \@bold($sender)\n");
305    } elsif ($m->is_zephyr && $m->is_mail) {
306        $out = "\@bold(MAIL) ";
307        if ($m->body =~ /^From:\s+(.+)\s*$/m) { $out .= "From $1 "; }
308        if ($m->body =~ /^To:\s+(.+)\s*$/m) { $out .= "To $1 "; }
309        if ($m->body =~ /^Subject:\s+(.+)\s*$/m) { $out .= "Subject $1 "; }
310        return($out);
311    }
312
313    if ($m->is_zephyr) {
314        $out = sprintf "[mit,%s,%s] / %s / %s", lc($m->class), 
315        lc($m->instance), $m->time, lc($m->host);
316        if ($m->opcode ne "") {$out.=" op:".$m->opcode;}
317        $out.="\n";
318        $out.= "  \@bold($sender)> ";
319        if ($m->zsig ne "") {
320            my $zsig = $m->zsig;
321            $zsig =~ s/(\n.*)+$/ [...]/;
322            if (length($zsig)+5+length($sender) > 70) {
323                $out.="# ...";
324            } else {
325                $out.="# $zsig";
326            }
327        }
328        $out.="\n";             
329    } else {
330        $out = sprintf "[%s] / %s\n", lc($m->type), $m->time;
331        $out.= "  \@bold($sender)> ";
332        $out.="\n";             
333    }
334
335    $out.=indent4($m->body);
336
337    # make personal messages bold
338    if ($m->is_personal) {
339        $out="\@bold{".$out."}";
340    }
341
342    return($out."\n");
343}
344
345sub format_msg_debug {
346    my ($m) = @_;
347    return "\@bold(-------------MESSAGE-------------)\n".($m->serialize).".\n";
348}
349
350sub format_msg_brief {
351    my ($m) = @_;
352    my $out = format_msg_vt($m);
353    $out =~ s/\n/ /g;
354    $out =~ s/                        / /g;
355    return($out."\n");
356}
357
358
359sub format_msg_vt {
360    my ($m) = @_;
361    my ($out, $tmp);
362
363    if ($m->is_admin) {
364        $out = sprintf "%-29s \@i(%s)", "\@bold(OWL ADMIN)", $m->header;
365        $tmp=$m->body;
366        $tmp=~s/^/                       /g;
367        $tmp=~s/\n/\n                       /g;
368        $out.="\n".$tmp;
369        return $out;
370    }
371
372    my $sender=$m->pretty_sender;
373
374    if ($m->is_outgoing) {
375        my $target = $m->recipient;
376        if ($m->is_zephyr) {
377            $target = $m->zwriteline;
378            $target =~ s/^zwrite //;
379        }
380        $out = sprintf "%-15s %-13s", "\@bold(OUTGOING)", "to $target via ".$m->type.": ";
381        my $pagewidth = owl::getnumcols()-6;
382        $out .= fill_text($m->body, $pagewidth, 22, 1);
383        return $out;
384    }
385
386    if (!$m->is_zephyr && !$m->is_aim) { 
387        return "Unknown message type: ".$m->type."\n";
388    }
389
390    if ($m->is_zephyr && $m->is_ping) {
391        return (sprintf "%-15s %-13s\n", "\@bold(PING)", $sender);
392    } elsif ($m->is_loginout) {
393        my $state;
394        if ($m->is_login) {
395            $state="\@bold(LOGIN)";
396        } elsif ($m->is_logout) {
397            $state="\@bold(LOGOUT)";
398        } else {
399            $state="\@bold(UNKNOWN)";
400        }
401        my $out = sprintf "%-15s %-13s ", $state, $sender;
402        if ($m->is_zephyr) {
403            $out .= sprintf "via %s on %s at %s", $m->type, $m->login_host, $m->login_tty;
404        } else {
405            $out .= sprintf "via %s", $m->type;
406        }
407        return "$out\n";
408               
409    } elsif ($m->is_zephyr && $m->is_mail) {
410        my $body = $m->body;
411        $out = sprintf "%-15s %-13s ", "\@bold(MAIL)", "";
412        if ($body =~ /^From:\s+(.+)\s*$/m) { $out .= "From $1 "; }
413        if ($body =~ /^To:\s+(.+)\s*$/m) { $out .= "To $1 "; }
414        if ($body =~ /^Subject:\s+(.+)\s*$/m) { $out .= "Subject $1 "; }
415        return($out."\n");
416    }
417
418    my $channel = "";
419    my $body = $m->body;
420   
421    if ($m->is_zephyr) {
422        my $inst = $m->instance;
423        $channel = $m->class;
424        if (lc($m->class) ne "message" and lc($m->instance) eq "personal") {
425            $inst = "";
426        }
427        $channel .= "[".$inst."]";
428        $channel = substr($channel,0,13);
429    } else {
430        $channel = "[".$m->type."]";
431    }
432
433    $header = sprintf "%-8s %-13s ", lc($sender), lc($channel);
434
435    if ($body =~ /=/) {
436        # indent it
437        $out.=$header."\n".indent4($body);
438    } else {
439        # fill it
440        my $pagewidth = owl::getnumcols()-6;
441        $out .= $header;
442        $out .= fill_text($body, $pagewidth, 22, 1);
443    }
444
445    # note: no zsig added in this version
446
447    # make personal messages bold
448    if ($m->is_personal) {
449        $out="\@bold{".$out."}";
450    }
451    return($out);
452}
453
454sub fill_text {
455    my ($in, $width, $indent, $unindent_first) = @_;
456    $indent = 0 if (@_ < 3);
457    my $unindent = $indent if ($unindent_first);
458    my @words = split " ", $in;
459    my $out = "";
460    my $outline = "";
461    if (!$unindent_first) {
462        my $outline = " "x$indent;
463    }
464    for my $w (@words) {
465        if (($outline ne "") 
466            && (length($outline)+length($w) > $width-$unindent)) {
467            $out .= $outline."\n";
468            $outline = " "x$indent;
469            $unindent = 0;
470        }
471        if ($outline =~ /.*\.$/) {
472            $outline .= "  ";
473        } elsif ($outline ne "") {
474            $outline .= " ";
475        }
476        $outline .= $w;
477    }
478    $out .= $outline . "\n";   
479}
Note: See TracBrowser for help on using the repository browser.