Skip to content
Newer
Older
100755 58 lines (48 sloc) 1.06 KB
b288607 @tadzik Initial commit
authored Jan 29, 2012
1 #!/usr/bin/env perl6
2 use Term::ANSIColor;
3
4 my @tasks;
5 my $yay = colored('', 'green');
6 my $nay = colored('', 'red');
7
8 INIT {
9 @tasks = lines(slurp('tasks')).map: {
10 next if $_ eq '';
11 $_.substr(1) => ($_.substr(0, 1) eq '+')
12 }
13 }
14
3bcff51 @tadzik Document
authored Jan 29, 2012
15 #= add a new TODO item
b288607 @tadzik Initial commit
authored Jan 29, 2012
16 multi MAIN(*@words) {
17 @tasks.push: @words.join(' ') => 0;
18 }
19
3bcff51 @tadzik Document
authored Jan 29, 2012
20 #= remove an item at the desired index
b288607 @tadzik Initial commit
authored Jan 29, 2012
21 multi MAIN('rm', Int $which) {
22 @tasks.splice($which, 1);
23 }
24
3bcff51 @tadzik Document
authored Jan 29, 2012
25 #= list [--all] items (only the incomplete ones by default)
b288607 @tadzik Initial commit
authored Jan 29, 2012
26 multi MAIN('ls', Bool :$all) {
27 for @tasks.kv -> $i, $t {
28 if $all or !$t.value {
29 say "#$i {$t.value ?? $yay !! $nay} {$t.key}"
30 }
31 }
32 }
33
3bcff51 @tadzik Document
authored Jan 29, 2012
34 #= mark an item as done
b288607 @tadzik Initial commit
authored Jan 29, 2012
35 multi MAIN('check', Int $which) {
36 @tasks[$which].value = 1
37 }
38
3bcff51 @tadzik Document
authored Jan 29, 2012
39 #= mark an item as undone
b288607 @tadzik Initial commit
authored Jan 29, 2012
40 multi MAIN('undo', Int $which) {
41 @tasks[$which].value = 0
42 }
43
3bcff51 @tadzik Document
authored Jan 29, 2012
44 #= clear the list
b288607 @tadzik Initial commit
authored Jan 29, 2012
45 multi MAIN('clear') {
46 @tasks = ();
47 }
48
49 END {
50 my $repr = @tasks.map({
51 ($_.value ?? '+' !! '-') ~ $_.key
52 }).join("\n");
53 given open 'tasks', :w {
54 .say($repr);
55 .close;
56 }
57 }
Something went wrong with that request. Please try again.