Add support for i3status-rust

This commit is contained in:
Brian Buller 2021-04-29 10:11:51 -05:00
parent 00e13fc7ad
commit 2ba309fe36
3 changed files with 48 additions and 0 deletions

View File

@ -167,6 +167,10 @@ func (a *AppState) initialize() {
}
a.ValidOperations = make(map[string][]string)
a.OpFuncs = make(map[string]func([]string) int)
a.addOperation("i3status",
[]string{"i3status - Output json appropriate for an i3status-rust block"},
a.opI3Status,
)
a.addOperation("ls",
[]string{"ls - List Tasks"},
a.opListTasks,

View File

@ -3,7 +3,10 @@ package main
import (
"strconv"
"strings"
"time"
"unicode"
todotxt "git.bullercodeworks.com/brian/go-todotxt"
)
func itoa(val int) string {
@ -76,3 +79,15 @@ func sliceIsValidTags(v []string) bool {
}
return true
}
func copyTaskList(t todotxt.TaskList) todotxt.TaskList {
re := todotxt.NewTaskList()
for _, v := range t {
re.AddTask(&v)
}
return *re
}
func dateWithinNextDay(d time.Time) bool {
return !d.IsZero() && d.Before(time.Now().Add(time.Hour*24))
}

View File

@ -8,6 +8,35 @@ import (
todotxt "git.bullercodeworks.com/brian/go-todotxt"
)
func (a *AppState) opI3Status(args []string) int {
var filterString string
state := "Idle"
if len(args) > 0 {
filterString = strings.Join(args, " ")
a.TaskList = a.getFilteredList(filterString)
}
total := len(*a.TaskList)
var incomplete int
for _, v := range *a.TaskList {
if !v.HasCompletedDate() {
incomplete++
if dateWithinNextDay(v.DueDate) {
state = "Warning"
}
}
}
if state != "Warning" {
warning := a.config.Get("i3status_warning")
if warning != "" {
if len(*a.getFilteredList(warning)) > 0 {
state = "Warning"
}
}
}
fmt.Printf("{\"icon\":\"tasks\",\"state\":\"%s\", \"text\": \"%s: %d/%d\"}", state, filterString, incomplete, total)
return 0
}
func (a *AppState) opListTasks(args []string) int {
var lastIdx int
var filterString string