pomodoro support

This commit is contained in:
Dan Ballard 2018-05-29 09:41:30 -07:00
parent 4204f610a0
commit 4941a346be
7 changed files with 55 additions and 21 deletions

View File

@ -32,3 +32,9 @@
- [ ] Group
- [ ] 0x3 nesting rep
- [x] 2x6 done nested rep
# Pomodoros
- [ ] not done
- [..] partly done
- [x...] completed

View File

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

View File

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

View File

@ -42,3 +42,9 @@
- [ ] 0x2 other things
- category
- [x] 2x10 nested rep
# Pomodoros
- [ ] not done
- [..] partly done
- [x...] completed

View File

@ -16,7 +16,7 @@ type header struct {
type processHandler struct {
File *os.File
totalCount, doneCount int
totalCount, doneCount, pomodoroCount int
headers []header
}
@ -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() {
@ -75,6 +80,7 @@ func (ph *processHandler) ProcessLine(line string, indentLevel int, headerStack
}
ph.Writeln("\t\t" + repStr + strings.Join(lineStack, " / "))
}
ph.pomodoroCount += flags.Pomodoros
}
func main() {

View File

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

View File

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