Skip to content

Commit

Permalink
Add a visual timeline so you can see your progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
nige123 committed Jan 12, 2019
1 parent 55710ea commit bd5095a
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 16 deletions.
4 changes: 2 additions & 2 deletions META6.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"perl" : "6",
"name" : "Do123",
"version" : "0.2",
"version" : "0.3",
"auth" : "github:nige123",
"description" : "a timeline to help your work flow: do, doing, done",
"license" : "Artistic-2.0",
"depends" : ["Terminal::ANSIColor", "jmp" ],
"depends" : ["Terminal::Print", "jmp" ],
"provides" : {
"Do" : "lib/Do.pm",
"Do::CLI" : "lib/Do/CLI.pm",
Expand Down
13 changes: 12 additions & 1 deletion lib/Do.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@ use Do::Timeline;
class Do {

has $.file;
has $.timeline handles qw<add edit find get-entry move render render-day remove>;
has $.timeline handles
qw<
add edit
estimate-tasks-per-day
find
get-entry
move
render
render-day
remove
show-graph
>;

submethod TWEAK {
$!timeline = Do::Timeline.new(file => $!file);
Expand Down
19 changes: 11 additions & 8 deletions lib/Do/CLI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,14 @@ sub USAGE is export {

}


my $do-file-location = find-nearest-file();

my $do = Do.new(file => $do-file-location);

sub find-nearest-file {

my $file-path = $*CWD.path;

my $loop-counter;
my $file-path = $*CWD.path;

loop {
my $do-file = $file-path.IO.add('123.do');
Expand All @@ -78,7 +76,6 @@ sub find-nearest-file {

}


# show a section of the timeline
multi sub MAIN ($arg1 where /<Do::Timeline::Grammar::entry>/) {

Expand Down Expand Up @@ -112,8 +109,7 @@ multi sub MAIN ($entry-id, $arg2 where /<Do::Timeline::Grammar::entry>/) {

}

multi sub MAIN ('mv', $entry-id, $arg2 where /<Do::Timeline::Grammar::entry>/) {

multi sub MAIN ('mv', $entry-id, $arg2 where /<Do::Timeline::Grammar::entry>/) {
MAIN($entry-id, $arg2);
}

Expand Down Expand Up @@ -150,6 +146,8 @@ multi sub MAIN ('do', *@entry) { MAIN('+', @entry) }
multi sub MAIN ('doing', *@entry) { MAIN('!', @entry) }
multi sub MAIN ('done', *@entry) { MAIN('-', @entry) }

multi sub MAIN ('help') { USAGE() }

multi sub MAIN ('mv', UInt $entry-id, 'today') { MAIN($entry-id, '!') }
multi sub MAIN ('mv', UInt $entry-id, 'now') { MAIN($entry-id, '!') }
multi sub MAIN ('mv', UInt $entry-id, 'yesterday') { MAIN($entry-id, '-1') }
Expand Down Expand Up @@ -181,8 +179,7 @@ multi sub MAIN ('find', *@search-terms) {

}


# change the 123.do file with your favourite $EDITOR
# edit the 123.do file with your favourite $EDITOR
multi sub MAIN ('edit') { $do.edit; }

# look for a specific entry id - and drop the user off there
Expand All @@ -208,3 +205,9 @@ multi sub MAIN ('rm', *@entry-ids where { $_.all ~~ UInt }) {

}

# show timeline statistics
multi sub MAIN {
say $do.show-graph();
}


23 changes: 19 additions & 4 deletions lib/Do/Timeline.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#---------------------------------------------------------------------------------------
#
# 123 - a timeline to help your work flow: do -> doing -> done
# 123.do - a timeline to help your work flow: do -> doing -> done
#
# Author: Nigel Hamilton ([email protected])
# Copyright licence: Artistic 2.0
Expand All @@ -13,8 +13,9 @@ use Do::Editor;
use Do::Timeline::Entry;
use Do::Timeline::Grammar;
use Do::Timeline::Viewport;
use Do::Timeline::UI;

class Do::Timeline does Do::Timeline::Viewport {
class Do::Timeline does Do::Timeline::Viewport does Do::Timeline::UI {

has $.file;
has %.entries;
Expand Down Expand Up @@ -84,22 +85,36 @@ class Do::Timeline does Do::Timeline::Viewport {
my $entry-at-line = $.file.IO.slurp.match(/^ .*? '[' $entry-id ']'/).lines.elems // 1;
self.open-editor-at-line($entry-at-line);
}

multi method edit-matching-line (Str $match-string, $offset = 0) {
my $line-number = 1;
for $.file.IO.slurp.lines -> $line {
last if $line.starts-with($match-string);
$line-number++;
}

Do::Editor.new.open($!file, $line-number + $offset);

# reload the 123.do file and save any changes - this enables entries to move
self.load;
self.save;
}

multi method edit {
# which line is NOW on in the 123.do file?
my $now-at-line = $.file.IO.slurp.match(/^.*?^^NOW/).lines.elems // 0;
self.open-editor-at-line(1 + $now-at-line);
}

submethod estimate-tasks-per-day {
method estimate-tasks-per-day {
my %past-entries = self.entries.values.map(*.Slip).grep(*.is-past).classify(*.daycount);

# default to 6 tasks per day
return 6 unless %past-entries;

my @past-day-entry-counts = %past-entries.values.map(*.elems);

# average daily velocity previously in the past
# average daily velocity based on previously completed tasks in the past
return @past-day-entry-counts.sum div @past-day-entry-counts.elems;
}

Expand Down
21 changes: 20 additions & 1 deletion lib/Do/Timeline/Viewport.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env perl6

# render parts of the timeline for display and storage
# render parts of the timeline for display and file storage
role Do::Timeline::Viewport {

method render (%timeline-entries = %.entries) {
Expand All @@ -11,6 +11,25 @@ role Do::Timeline::Viewport {
multi method render-day ('-', $past-offset) { self.render-day(Date.today.daycount - $past-offset) }
multi method render-day ('!', $now-offset) { self.render-day(Date.today.daycount) }
multi method render-day ('+', $next-offset) { self.render-day(Date.today.daycount + $next-offset) }

multi method render-day-with-padding (Int $daycount, $pad-to-width = 80) {

my ($space, $heading, @entry-lines) = self.render-day($daycount).lines;

my $left-padding = ' ' x ($pad-to-width - $heading.chars) div 2;
my $right-padding = ' ' x $pad-to-width - ($heading.chars + $left-padding);

my @padded-lines;

@padded-lines.push($left-padding ~ $heading ~ $right-padding);

for @entry-lines -> $line {
@padded-lines.push($line ~ ' ' x ($pad-to-width - $line.chars));
}

return @padded-lines.join("\n");

}

multi method render-day (Int $daycount) {

Expand Down

0 comments on commit bd5095a

Please sign in to comment.