pomodoro support
This commit is contained in:
parent
4204f610a0
commit
4941a346be
|
@ -32,3 +32,9 @@
|
||||||
- [ ] Group
|
- [ ] Group
|
||||||
- [ ] 0x3 nesting rep
|
- [ ] 0x3 nesting rep
|
||||||
- [x] 2x6 done nested rep
|
- [x] 2x6 done nested rep
|
||||||
|
|
||||||
|
# Pomodoros
|
||||||
|
|
||||||
|
- [ ] not done
|
||||||
|
- [..] partly done
|
||||||
|
- [x...] completed
|
||||||
|
|
|
@ -45,6 +45,8 @@ func (ph *processHandler) ProcessLine(line string, indentLevel int, headerStack
|
||||||
if !flags.Done || flags.RepTask.Is {
|
if !flags.Done || flags.RepTask.Is {
|
||||||
if flags.RepTask.Is {
|
if flags.RepTask.Is {
|
||||||
ph.Writeln(strings.Repeat("\t", indentLevel) + "- [ ] 0x" + strconv.Itoa(flags.RepTask.B) + " " + lineStack[len(lineStack)-1])
|
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 {
|
} else {
|
||||||
ph.Writeln(line)
|
ph.Writeln(line)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,16 +12,16 @@ import (
|
||||||
const EXPECTED = `# Work
|
const EXPECTED = `# Work
|
||||||
|
|
||||||
- [ ] Write tests
|
- [ ] Write tests
|
||||||
- [ ] migrate
|
- [ ] migrate
|
||||||
|
|
||||||
# Test Data
|
# Test Data
|
||||||
|
|
||||||
- note
|
- note
|
||||||
-
|
-
|
||||||
- [ ] nesting1
|
- [ ] nesting1
|
||||||
- [ ] nesting 2
|
- [ ] nesting 2
|
||||||
- [ ] nesting 3
|
- [ ] nesting 3
|
||||||
- [ ] nesting 4
|
- [ ] nesting 4
|
||||||
-
|
-
|
||||||
asdasd
|
asdasd
|
||||||
- tabbing
|
- tabbing
|
||||||
|
@ -39,6 +39,11 @@ const EXPECTED = `# Work
|
||||||
- [ ] Group
|
- [ ] Group
|
||||||
- [ ] 0x3 nesting rep
|
- [ ] 0x3 nesting rep
|
||||||
- [ ] 0x6 done nested rep
|
- [ ] 0x6 done nested rep
|
||||||
|
|
||||||
|
# Pomodoros
|
||||||
|
|
||||||
|
- [ ] not done
|
||||||
|
- [ ] partly done
|
||||||
`
|
`
|
||||||
|
|
||||||
func TestMigrate(t *testing.T) {
|
func TestMigrate(t *testing.T) {
|
||||||
|
|
|
@ -41,4 +41,10 @@
|
||||||
- [x] 5x5 things
|
- [x] 5x5 things
|
||||||
- [ ] 0x2 other things
|
- [ ] 0x2 other things
|
||||||
- category
|
- category
|
||||||
- [x] 2x10 nested rep
|
- [x] 2x10 nested rep
|
||||||
|
|
||||||
|
# Pomodoros
|
||||||
|
|
||||||
|
- [ ] not done
|
||||||
|
- [..] partly done
|
||||||
|
- [x...] completed
|
|
@ -15,9 +15,9 @@ type header struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type processHandler struct {
|
type processHandler struct {
|
||||||
File *os.File
|
File *os.File
|
||||||
totalCount, doneCount int
|
totalCount, doneCount, pomodoroCount int
|
||||||
headers []header
|
headers []header
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ph *processHandler) Writeln(line string) {
|
func (ph *processHandler) Writeln(line string) {
|
||||||
|
@ -27,11 +27,16 @@ func (ph *processHandler) Writeln(line string) {
|
||||||
func (ph *processHandler) NewFile() {
|
func (ph *processHandler) NewFile() {
|
||||||
ph.totalCount = 0
|
ph.totalCount = 0
|
||||||
ph.doneCount = 0
|
ph.doneCount = 0
|
||||||
|
ph.pomodoroCount = 0
|
||||||
ph.headers = []header{}
|
ph.headers = []header{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ph *processHandler) Eof() {
|
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() {
|
func (ph *processHandler) handleHeaderPrint() {
|
||||||
|
@ -69,12 +74,13 @@ func (ph *processHandler) ProcessLine(line string, indentLevel int, headerStack
|
||||||
ph.doneCount += 1
|
ph.doneCount += 1
|
||||||
repStr := ""
|
repStr := ""
|
||||||
if flags.RepTask.Is {
|
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
|
// 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.totalCount += 1
|
||||||
}
|
}
|
||||||
ph.Writeln("\t\t" + repStr + strings.Join(lineStack, " / "))
|
ph.Writeln("\t\t" + repStr + strings.Join(lineStack, " / "))
|
||||||
}
|
}
|
||||||
|
ph.pomodoroCount += flags.Pomodoros
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -22,7 +22,9 @@ const EXPECTED = `
|
||||||
# Repetition
|
# Repetition
|
||||||
25 things
|
25 things
|
||||||
20 category / nested rep
|
20 category / nested rep
|
||||||
6 / 16
|
# Pomodoros
|
||||||
|
completed
|
||||||
|
7 / 19 - 5 Pomodoros
|
||||||
`
|
`
|
||||||
|
|
||||||
func TestSummary(t *testing.T) {
|
func TestSummary(t *testing.T) {
|
||||||
|
|
|
@ -11,6 +11,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
todoTaskExp = regexp.MustCompile("^\\[([ \\.xX]*)\\]")
|
||||||
|
startSpaces = regexp.MustCompile("^[\t ]*")
|
||||||
repTaskRegExp = regexp.MustCompile("^([0-9]*)[xX]([0-9]*)")
|
repTaskRegExp = regexp.MustCompile("^([0-9]*)[xX]([0-9]*)")
|
||||||
headerExp = regexp.MustCompile("^(#+) *(.+)")
|
headerExp = regexp.MustCompile("^(#+) *(.+)")
|
||||||
)
|
)
|
||||||
|
@ -24,6 +26,7 @@ type Flags struct {
|
||||||
Todo bool
|
Todo bool
|
||||||
Done bool
|
Done bool
|
||||||
RepTask RepTask
|
RepTask RepTask
|
||||||
|
Pomodoros int
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProcessHandler interface {
|
type ProcessHandler interface {
|
||||||
|
@ -73,7 +76,6 @@ func ProcessFile(ph ProcessHandler, fileName string) {
|
||||||
|
|
||||||
scanner := bufio.NewScanner(file)
|
scanner := bufio.NewScanner(file)
|
||||||
indentPattern := ""
|
indentPattern := ""
|
||||||
startSpaces := regexp.MustCompile("^[\t ]*")
|
|
||||||
indentLevel := 0
|
indentLevel := 0
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := scanner.Text()
|
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) {
|
func getText(str string, indentLevel int, indentPattern string) (text string, flags Flags) {
|
||||||
//fmt.Printf("indentLevel: %v str: '%s'\n", indentLevel, str )
|
//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.Done = false
|
||||||
flags.Todo = false
|
flags.Todo = false
|
||||||
flags.RepTask.Is = 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
|
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
|
flags.Done = true
|
||||||
}
|
}
|
||||||
if len(text) > 4 {
|
flags.Pomodoros = strings.Count(inner, ".")
|
||||||
text = text[4:]
|
if len(text) > len(inner) + 3 {
|
||||||
|
text = text[len(inner)+3:]
|
||||||
}
|
}
|
||||||
|
|
||||||
if repTaskRegExp.MatchString(text) {
|
if repTaskRegExp.MatchString(text) {
|
||||||
|
|
Loading…
Reference in New Issue