From 4941a346be8a9fcf7b96c1e7862eca3a665d6a99 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Tue, 29 May 2018 09:41:30 -0700 Subject: [PATCH] pomodoro support --- mdbj-migrate/2018-05-07-TEST.md | 6 ++++++ mdbj-migrate/migrate.go | 2 ++ mdbj-migrate/migrate_test.go | 13 +++++++++---- mdbj-summary/2018-05-07-TEST.md | 8 +++++++- mdbj-summary/summary.go | 16 +++++++++++----- mdbj-summary/summary_test.go | 4 +++- process/process.go | 27 +++++++++++++++++---------- 7 files changed, 55 insertions(+), 21 deletions(-) diff --git a/mdbj-migrate/2018-05-07-TEST.md b/mdbj-migrate/2018-05-07-TEST.md index d833d47..31a9871 100644 --- a/mdbj-migrate/2018-05-07-TEST.md +++ b/mdbj-migrate/2018-05-07-TEST.md @@ -32,3 +32,9 @@ - [ ] Group - [ ] 0x3 nesting rep - [x] 2x6 done nested rep + +# Pomodoros + +- [ ] not done +- [..] partly done +- [x...] completed diff --git a/mdbj-migrate/migrate.go b/mdbj-migrate/migrate.go index 6075d36..b8dbad5 100644 --- a/mdbj-migrate/migrate.go +++ b/mdbj-migrate/migrate.go @@ -45,6 +45,8 @@ func (ph *processHandler) ProcessLine(line string, indentLevel int, headerStack if !flags.Done || flags.RepTask.Is { if flags.RepTask.Is { ph.Writeln(strings.Repeat("\t", indentLevel) + "- [ ] 0x" + strconv.Itoa(flags.RepTask.B) + " " + lineStack[len(lineStack)-1]) + } else if flags.Todo { + ph.Writeln(strings.Repeat("\t", indentLevel) + "- [ ] " + lineStack[len(lineStack)-1]) } else { ph.Writeln(line) } diff --git a/mdbj-migrate/migrate_test.go b/mdbj-migrate/migrate_test.go index 8da58e5..36c9e18 100644 --- a/mdbj-migrate/migrate_test.go +++ b/mdbj-migrate/migrate_test.go @@ -12,16 +12,16 @@ import ( const EXPECTED = `# Work - [ ] Write tests - - [ ] migrate + - [ ] migrate # Test Data - note - - [ ] nesting1 - - [ ] nesting 2 - - [ ] nesting 3 - - [ ] nesting 4 + - [ ] nesting 2 + - [ ] nesting 3 + - [ ] nesting 4 - asdasd - tabbing @@ -39,6 +39,11 @@ const EXPECTED = `# Work - [ ] Group - [ ] 0x3 nesting rep - [ ] 0x6 done nested rep + +# Pomodoros + +- [ ] not done +- [ ] partly done ` func TestMigrate(t *testing.T) { diff --git a/mdbj-summary/2018-05-07-TEST.md b/mdbj-summary/2018-05-07-TEST.md index 73cb543..d316d77 100644 --- a/mdbj-summary/2018-05-07-TEST.md +++ b/mdbj-summary/2018-05-07-TEST.md @@ -41,4 +41,10 @@ - [x] 5x5 things - [ ] 0x2 other things - category - - [x] 2x10 nested rep \ No newline at end of file + - [x] 2x10 nested rep + +# Pomodoros + +- [ ] not done +- [..] partly done +- [x...] completed \ No newline at end of file diff --git a/mdbj-summary/summary.go b/mdbj-summary/summary.go index 23befb2..c734e62 100644 --- a/mdbj-summary/summary.go +++ b/mdbj-summary/summary.go @@ -15,9 +15,9 @@ type header struct { } type processHandler struct { - File *os.File - totalCount, doneCount int - headers []header + File *os.File + totalCount, doneCount, pomodoroCount int + headers []header } func (ph *processHandler) Writeln(line string) { @@ -27,11 +27,16 @@ func (ph *processHandler) Writeln(line string) { func (ph *processHandler) NewFile() { ph.totalCount = 0 ph.doneCount = 0 + ph.pomodoroCount = 0 ph.headers = []header{} } func (ph *processHandler) Eof() { - ph.Writeln(strconv.Itoa(ph.doneCount) + " / " + strconv.Itoa(ph.totalCount)) + pomodoroStr := "" + if ph.pomodoroCount > 0 { + pomodoroStr = " - " + strconv.Itoa(ph.pomodoroCount) + " Pomodoros" + } + ph.Writeln(strconv.Itoa(ph.doneCount) + " / " + strconv.Itoa(ph.totalCount) + pomodoroStr) } func (ph *processHandler) handleHeaderPrint() { @@ -69,12 +74,13 @@ func (ph *processHandler) ProcessLine(line string, indentLevel int, headerStack ph.doneCount += 1 repStr := "" if flags.RepTask.Is { - repStr = strconv.Itoa(flags.RepTask.A * flags.RepTask.B) + " " + repStr = strconv.Itoa(flags.RepTask.A*flags.RepTask.B) + " " // inc todo count here since we did a thing, its done, and we dont want a higher done count than total ph.totalCount += 1 } ph.Writeln("\t\t" + repStr + strings.Join(lineStack, " / ")) } + ph.pomodoroCount += flags.Pomodoros } func main() { diff --git a/mdbj-summary/summary_test.go b/mdbj-summary/summary_test.go index 15c4cba..3301c96 100644 --- a/mdbj-summary/summary_test.go +++ b/mdbj-summary/summary_test.go @@ -22,7 +22,9 @@ const EXPECTED = ` # Repetition 25 things 20 category / nested rep -6 / 16 + # Pomodoros + completed +7 / 19 - 5 Pomodoros ` func TestSummary(t *testing.T) { diff --git a/process/process.go b/process/process.go index be735c7..095816c 100644 --- a/process/process.go +++ b/process/process.go @@ -11,6 +11,8 @@ import ( ) var ( + todoTaskExp = regexp.MustCompile("^\\[([ \\.xX]*)\\]") + startSpaces = regexp.MustCompile("^[\t ]*") repTaskRegExp = regexp.MustCompile("^([0-9]*)[xX]([0-9]*)") headerExp = regexp.MustCompile("^(#+) *(.+)") ) @@ -24,6 +26,7 @@ type Flags struct { Todo bool Done bool RepTask RepTask + Pomodoros int } type ProcessHandler interface { @@ -73,7 +76,6 @@ func ProcessFile(ph ProcessHandler, fileName string) { scanner := bufio.NewScanner(file) indentPattern := "" - startSpaces := regexp.MustCompile("^[\t ]*") indentLevel := 0 for scanner.Scan() { line := scanner.Text() @@ -125,21 +127,26 @@ func ProcessFile(ph ProcessHandler, fileName string) { func getText(str string, indentLevel int, indentPattern string) (text string, flags Flags) { //fmt.Printf("indentLevel: %v str: '%s'\n", indentLevel, str ) - if len(str) < (indentLevel*4 + 2) { - return "", Flags{false, false, RepTask{false, 0, 0}} - } - str = strings.TrimLeft(str, strings.Repeat(indentPattern, indentLevel)) - text = str[2:] flags.Done = false flags.Todo = false flags.RepTask.Is = false - if text[0] == '[' { + flags.Pomodoros = 0 + + if len(str) < (indentLevel*4 + 2) { + return "", flags + } + str = strings.TrimLeft(str, strings.Repeat(indentPattern, indentLevel)) + text = str[2:] + + if todoTaskExp.MatchString(text) { flags.Todo = true - if text[1] == 'x' || text[1] == 'X' { + inner := string(todoTaskExp.FindSubmatch([]byte(text))[1]) + if strings.ContainsAny(inner, "xX") { flags.Done = true } - if len(text) > 4 { - text = text[4:] + flags.Pomodoros = strings.Count(inner, ".") + if len(text) > len(inner) + 3 { + text = text[len(inner)+3:] } if repTaskRegExp.MatchString(text) {