-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormat.pm
731 lines (565 loc) · 13.7 KB
/
Format.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
package Hier::Format;
use strict;
use warnings;
BEGIN {
use Exporter ();
our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
# set the version for version checking
$VERSION = 1.00;
@ISA = qw(Exporter);
@EXPORT = qw(
&report_header &count_children &summary_line
&display_mode &display_fd_task &display_task
&display_rgpa &display_hier
&disp_ordered_dump
);
}
use Hier::util;
use Hier::Option;
my $Display = \&disp_simple;
my $Header = undef;
my $Wiki = 0; #### display is in wiki format ####
my @Order = (qw(
todo_id
type
nextaction
isSomeday
.
task
description
note
.
category
context
timeframe
.
created
doit
modified
tickledate
due
completed
recur
recurdesc
.
owner
palm_id
priority
effort
resource
depends
private
percent
.
) );
sub display_mode {
my($mode) = @_;
my(%alias) = (
'todo' => 'doit',
'pri' => 'priority',
);
# alias re-mappings
$mode = lc($mode);
if (defined $alias{$mode}) {
$mode = $alias{$mode};
}
if ($mode eq 'wiki') {
$Wiki = 1;
}
my(%mode) = (
'none' => \&disp_none,
'tid' => \&disp_tid,
'list' => \&disp_tid,
'title' => \&disp_title,
'item' => \&disp_item,
'simple' => \&disp_simple,
'summary' => \&disp_summary,
'detail' => \&disp_detail,
'task' => \&disp_task,
'doit' => \&disp_task,
'html' => \&disp_html,
'wiki' => \&disp_wiki,
'd_csv' => \&disp_doit_csv,
'd_lst' => \&disp_doit_list,
'rpga' => \&disp_rgpa,
'rgpa' => \&disp_rgpa,
'hier' => \&disp_hier,
'priority' => \&disp_priority,
'dump' => \&disp_ordered_dump,
'udump' => \&disp_unordered_dump,
'odump' => \&disp_ordered_dump,
);
my(%report) = (
'none' => 'none',
'tid' => 'report',
'list' => 'report',
'title' => 'report',
'item' => 'report',
'simple' => 'report',
'summary' => 'report',
'detail' => 'report',
'task' => 'report',
'doit' => 'report',
'html' => 'html',
'wiki' => 'wiki',
'd_csv' => 'report',
'd_lst' => 'report',
'rpga' => 'rgpa',
'rgpa' => 'rgpa',
'hier' => 'hier',
'priority' => 'report',
'dump' => 'none',
'udump' => 'none',
'sdump' => 'none',
'odump' => 'none',
);
my(%header) = (
'none' => \&header_none,
'report' => \&header_report,
'html' => \&header_html,
'wiki' => \&header_wiki,
'rgpa' => \&header_rgpa,
'hier' => \&header_hier,
);
$mode = 'simple' if $mode eq '';
if ($mode eq 'simple') {
$mode = 'tid' if option('List', 0);
}
# process header modes
unless (defined $mode{$mode}) {
warn "Unknown display mode: $mode\n";
return;
}
$Display = $mode{$mode};
$mode = option('Header', $mode);
$mode = $report{$mode} if defined $report{$mode};
$Header = $header{$mode} if defined $header{$mode};
# pick sorting?
return;
}
#==============================================================================
sub report_header {
my($title) = option('Title') || '';
if (@_) {
my($desc) = join(' ', @_) || '';
if ($title and $desc) {
$title .= ' -- ' . $desc;
} elsif ($title eq '') {
$title = $desc;
}
}
unless ($Header) {
display_mode('simple');
}
&$Header(\*STDOUT, $title);
}
sub count_children {
my($pref) = @_;
my $work_load = 0;
my $complet = 0;
my $counted = 0;
my $actions = 0;
for my $child ($pref->get_children()) {
$complet++ if $child->get_completed();
$actions++;
next unless $child->is_nextaction();
$counted++ unless $child->filtered();
$work_load++;
}
return ($work_load, "($counted/$actions/$complet)");
}
sub summary_line {
return format_summary(@_);
}
#==============================================================================
sub display_header {
&$Header(\*STDOUT, @_);
}
sub header_none {
}
sub header_report {
my($fd, $title) = @_;
my($cols) = columns() - 2;
print {$fd} '#',"=" x $cols, "\n";
print {$fd} "#== $title\n";
print {$fd} '#',"=" x $cols, "\n";
}
sub header_wiki {
my($fd, $title) = @_;
print {$fd} "== $title ==\n";
}
sub header_html {
my($fd, $title) = @_;
print {$fd} "<h1>$title</h1>\n";
}
sub display_task {
&$Display(\*STDOUT, @_);
}
sub display_fd_task {
&$Display(@_);
}
sub disp_none {
# no display
}
sub disp_tid {
my($fd, $ref) = @_;
my($tid) = $ref->get_tid();
print {$fd} $tid, "\n";
}
sub disp_title {
my($fd, $ref) = @_;
my($title) = $ref->get_title();
print {$fd} $title, "\n";
}
sub disp_item {
my($fd, $ref, $extra) = @_;
my($tid) = $ref->get_tid();
my($type) = type_disp($ref);
my($title) = $ref->get_task();
my($desc) = format_summary($ref->get_description(), ' -- ');
print {$fd} "$tid\t [_] $title$desc\n";
}
sub disp_simple {
my($fd, $ref, $extra) = @_;
my($tid) = $ref->get_tid();
my($type) = type_disp($ref);
my($title) = $ref->get_task();
if ($extra) {
$extra = ' '. $extra;
} else {
$extra = '';
}
print {$fd} "$tid:\t$type $title$extra\n";
}
sub disp_detail {
my($fd, $ref, $extra) = @_;
disp_simple(@_);
bulk_display('+', $ref->get_description());
bulk_display('=', $ref->get_note());
print "\n";
}
sub disp_summary {
my($fd, $ref, $extra) = @_;
my($desc) = format_summary($ref->get_description(), ' -- ');
disp_simple(@_, $desc);
}
sub format_summary {
my($val, $sep, $ishtml) = @_;
return '' unless $val;
return '' if $val =~ /^\s*[.\-\*]/;
$val =~ s/\n.*//s;
$val =~ s/\r.*//s;
return '' if $val eq '';
return '' if $val eq '=';
return $sep . $val;
}
sub bulk_display {
my($tag, $text) = @_;
return unless defined $text;
return if $text eq '';
return if $text eq '-';
for my $line (split("\n", $text)) {
print "$tag\t$line\n";
}
}
sub disp_bulklist {
}
sub disp_ordered_dump {
my($fd, $ref) = @_;
my $val;
for my $key (@Order) {
next if $key =~ /^_/;
if ($key eq '.') {
print $fd "\n";
next;
}
$val = $ref->get_KEY($key);
if (defined $val) {
chomp $val;
$val =~ s/\r//gm; # all returns
$val =~ s/^/\t\t/gm; # tab at start of line(s)
$val =~ s/^\t// if length($key) >= 7;
print $fd "$key:$val\n";
} else {
print $fd "#$key:\n";
}
}
###BUG### handle missing keys from @Ordered
print $fd "Tags:\t", $ref->disp_tags(),"\n";
print $fd "Parents:\t", $ref->disp_parents(),"\n";
print $fd "Children:\t", $ref->disp_children(),"\n";
print $fd "=-=\n\n";
}
sub disp_unordered_dump {
my($fd, $ref) = @_;
my $val;
for my $key (sort keys %$ref) {
next if $key =~ /^_/;
$val = $ref->get_KEY($key);
if (defined $val) {
chomp $val;
$val =~ s/\r//gm; # all returns
$val =~ s/^/\t\t/gm; # tab at start of line(s)
$val =~ s/^\t// if length($key) >= 7;
print $fd "$key:$val\n";
} else {
print $fd "#$key:\n";
}
}
print $fd "Tags:\t", $ref->disp_tags(),"\n";
print $fd "Parents:\t", $ref->disp_parents(),"\n";
print $fd "Children:\t", $ref->disp_children(),"\n";
print $fd "=-=\n\n";
}
my($Hier_stack) = { 'o' => 0, 'g' => 0, 'p' => 0 };
sub display_hier {
my($ref, $counts) = @_;
my($cols) = columns() - 2;
my $tid = $ref->get_tid();
my $type = $ref->get_type();
my $title = $ref->get_title();
if ($type eq 'o') {
if ($Hier_stack->{o}) {
print '#'.("=" x $cols), "\n";
}
$Hier_stack = { 'o' => $tid, 'g' => 0, 'p' => 0 };
$counts ||= '';
print " [*** Role $tid: $title ***] $counts\n";
return;
}
if ($type eq 'g') {
if ($Hier_stack->{g} ne $tid) {
display_hier($ref->get_parent());
if ($Hier_stack->{g}) {
print '#', "-" x $cols, "\n";
}
$Hier_stack->{g} = $tid;
$Hier_stack->{p} = 0;
}
}
if ($type eq 'p') {
if ($Hier_stack->{p} ne $tid) {
display_hier($ref->get_parent());
$Hier_stack->{p} = $tid;
}
}
display_task($ref, $counts);
}
my($Prev_goal) = 0;
my($Prev_role) = 0;
sub header_rgpa {
}
sub display_parent {
my($ref) = @_;
return unless $ref;
my $cols = columns() - 2;
my $tid = $ref->get_tid();
my $type = $ref->get_type();
if ($type eq 'o') { # 'o' == Role
return if $tid == $Prev_role;
if ($Wiki) {
display_task($ref);
} else {
print '#', "=" x $cols, "\n" if $Prev_role != 0;
print " [*** Role $tid: ", $ref->get_title(), " ***]\n";
}
$Prev_role = $tid;
$Prev_goal = 0;
return;
}
if ($type eq 'g') {
display_parent($ref->get_parent());
return if $tid == $Prev_goal;
if ($Wiki) {
display_task($ref);
} else {
print '#', "-" x $cols, "\n" if $Prev_goal != 0;
display_task($ref);
}
$Prev_goal = $tid;
return;
}
if ($type eq 'p') {
display_parent($ref->get_parent());
}
}
sub display_rgpa {
my($ref, $counts) = @_;
display_parent($ref->get_parent());
display_task($ref, $counts);
}
sub disp_wiki {
my($fd, $ref) = @_;
my(%type) = (
'a' => 'action',
'p' => 'project',
'g' => 'goal',
'o' => 'role',
'v' => 'value',
'm' => 'vision',
'w' => 'action',
'?' => 'fook',
);
my($type) = $ref->get_type();
my($tid) = $ref->get_tid();
my($title) = $ref->get_title();
my($done) = $ref->get_completed();
$type = '?' unless defined $type{$type};
print {$fd} '== ' if $type =~ /[ovm]/;
print {$fd} '=== ' if $type eq 'g';
print {$fd} '**' if $type eq 'a';
print {$fd} '*' if $type eq 'p';
print {$fd} "<del>" if $done;
print {$fd} '{{'.$type{$type},"|$tid|$title".'}}';
print {$fd} "</del>" if $done;
print {$fd} ' ===' if $type eq 'g';
print {$fd} ' ==' if $type =~ /[ovm]/;
print {$fd} "\n";
}
sub disp_task {
my($fd, $ref) = @_;
my($pri, $type, $context, $project, $action);
$type = $ref->get_type();
$context = $ref->get_context() || '';
$context = "\@$context" if $context;
if ($type eq 'a') {
my($proj) = $ref->get_parent();
if ($proj) {
$project = $proj->get_task();
$project =~ s/ /_/g;
$project = "/$project/"
} else {
}
} else {
$project = ' '.type_name($type).':';
}
$action = $ref->get_task();
my($tid) = '['.$ref->get_tid().']';
if ($ref->is_nextaction()) {
$pri = chr(ord('A') + ($ref->get_priority() || '4') - 1);
} else {
$pri = chr(ord('C') + ($ref->get_priority() || '4') - 1);
}
$pri = 'S' if $ref->get_isSomeday() eq 'y';
$pri = 'X' if $ref->get_completed();
$pri = 'V' if $type =~ /[mv]/;
$pri = 'I' if $type eq 'i';
$pri = 'R' if $type eq 'o';
$pri = 'Q' if $type eq 'g';
$pri = 'P' if $type eq 'p';
$pri = 'T' if $ref->get_tickledate() gt get_today();
$pri = 'L' if $type =~ /[rLCT]/;
my($result) = join(' ', "($pri)", $context.$project, $action, $tid);
$result =~ s/\s\s+/ /g;
print $result, "\n";
}
my($Count) = 0;
my @Lines;
sub disp_doit_csv {
my($fd, $ref) = @_;
my($tid, $pri, $task, $cat, $created, $modified,
$doit, $desc, $note, @desc);
$tid = $ref->get_tid();
$pri = $ref->get_priority();
$cat = $ref->get_category() || '';
$doit = $ref->get_doit() || '';
my($pref) = $ref->get_parent();
my($pname) = '-orphined-';
if (defined $pref) {
$pname = $pref->get_title();
}
$task = $ref->get_task() || $ref->get_context() || '';
$desc = $ref->get_description();
$desc =~ s/\n.*//s;
print {$fd} join("\t", $tid, $pri, $cat, $doit, $pname, $task, $desc), "\n";
#print join("\t", $tid, $pri, $cat, $task, $due, $desc), "\n";
}
sub header_doit_norm {
return if $Count++;
print <<"EOF";
Id Pri Category Doit Task/Description
==== === = ========= =========== ==============================================
EOF
}
sub display_doit_list {
my($ref) = @_;
my($tid, $pri, $task, $cat, $created, $modified,
$doit, $desc, $note, @desc);
format DOIT =
@>>> [_] @ @<<<<<<<< @<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$tid, $pri, $cat, $doit, $desc
~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$desc
.
header_doit_list();
$~ = "DOIT"; # set STDOUT format name to HIER
$tid = $ref->get_tid();
$pri = $ref->get_priority();
$task = $ref->get_task() || $ref->get_context() || '';
$cat = $ref->get_category() || '';
$created = $ref->get_created();
$modified = $ref->get_modified() || $created;
$doit = $ref->get_doit() || '';
$desc = $ref->get_description();
$note = $ref->get_note();
my($pid, $pref, $pname, $pdesc);
$pref = $ref->get_parent();
next unless defined $pref;
$pid = $pref->get_tid();
$pname = $pref->get_title();
$pdesc = $pref->get_description();
my($gid, $gref, $gname);
$gref = $pref->get_parent();
next unless defined $gref;
$gid = $gref->get_tid();
$gname = $gref->get_title();
chomp $gname;
chomp $pname;
chomp $pdesc;
chomp $task;
chomp $desc;
chomp $note;
$note = "Outcome: $note" if $note;
$desc = join("\r", "G[$gid]: $gname",
"P[$pid]: $pname",
split("\n", $pdesc),
"*[$tid] $task",
split("\n", $desc),
split("\n", $note)
);
write;
}
sub next_line {
my($v) = shift(@Lines);
$v ||= '';
return $v;
}
sub header_priority {
my($fd, $title) = @_;
format PRIO_TOP =
Id Pri Category Due Task/Description: $title
==== === = ========= =========== ==============================================
.
}
sub disp_priority {
my($fd, $ref) = @_;
my($tid, $key, $pri, $task, $cat, $created, $modified, $due, $desc);
format PRIO =
@>>> @<< @ @<<<<<<<< @<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$tid,$key,$pri, $cat, $due, $task
~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$desc
.
$~ = "PRIO"; # set STDOUT format name to PRIO
$tid = $ref->get_tid();
$pri = $ref->get_priority();
$task = $ref->get_task() || $ref->get_context() || '';
$cat = $ref->get_category() || '';
$created = $ref->get_created();
$modified = $ref->get_modified() || $created;
$due = $ref->get_due();
$desc = $ref->get_description() || '';
$key = action_disp($ref);
write;
}
1;