Skip to content

Instantly share code, notes, and snippets.

@tadzik
Created January 29, 2012 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tadzik/1699271 to your computer and use it in GitHub Desktop.
Save tadzik/1699271 to your computer and use it in GitHub Desktop.
Todo list, modeled after https://github.com/vesln/todo/
#!/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