Created
January 29, 2012 15:22
-
-
Save tadzik/1699271 to your computer and use it in GitHub Desktop.
Todo list, modeled after https://github.com/vesln/todo/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl6 | |
use Term::ANSIColor; | |
my @tasks; | |
my $yay = colored('√', 'green'); | |
my $nay = colored('✖', 'red'); | |
INIT { | |
@tasks = lines(slurp('tasks')).map: { | |
next if $_ eq ''; | |
$_.substr(1) => ($_.substr(0, 1) eq '+') | |
} | |
} | |
multi MAIN(*@words) { | |
@tasks.push: @words.join(' ') => 0; | |
} | |
multi MAIN('rm', Int $which) { | |
@tasks = @tasks[0..($which - 1)], @tasks[($which + 1)..*]; | |
} | |
multi MAIN('ls', Bool :$all) { | |
for @tasks.kv -> $i, $t { | |
if $all or !$t.value { | |
say "#$i {$t.value ?? $yay !! $nay} {$t.key}" | |
} | |
} | |
} | |
multi MAIN('check', Int $which) { | |
@tasks[$which].value = 1 | |
} | |
multi MAIN('undo', Int $which) { | |
@tasks[$which].value = 0 | |
} | |
multi MAIN('clear') { | |
@tasks = (); | |
} | |
END { | |
my $repr = @tasks.map({ | |
($_.value ?? '+' !! '-') ~ $_.key | |
}).join("\n"); | |
given open 'tasks', :w { | |
.say($repr); | |
.close; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment