Browse Source

pomodoro support

master
Dan Ballard 4 years ago
parent
commit
4941a346be
  1. 6
      mdbj-migrate/2018-05-07-TEST.md
  2. 2
      mdbj-migrate/migrate.go
  3. 13
      mdbj-migrate/migrate_test.go
  4. 8
      mdbj-summary/2018-05-07-TEST.md
  5. 16
      mdbj-summary/summary.go
  6. 4
      mdbj-summary/summary_test.go
  7. 25
      process/process.go

6
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

2
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)
}

13
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) {

8
mdbj-summary/2018-05-07-TEST.md

@ -41,4 +41,10 @@
- [x] 5x5 things
- [ ] 0x2 other things
- category
- [x] 2x10 nested rep
- [x] 2x10 nested rep
# Pomodoros
- [ ] not done
- [..] partly done
- [x...] completed

16
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() {

4
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) {

25
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 )
flags.Done = false
flags.Todo = false
flags.RepTask.Is = false
flags.Pomodoros = 0
if len(str) < (indentLevel*4 + 2) {
return "", Flags{false, false, RepTask{false, 0, 0}}
return "", flags
}
str = strings.TrimLeft(str, strings.Repeat(indentPattern, indentLevel))
text = str[2:]
flags.Done = false
flags.Todo = false
flags.RepTask.Is = false
if text[0] == '[' {
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) {

Loading…
Cancel
Save