package main import ( "fmt" "strconv" "strings" 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 showAll := len(args) > 0 && args[0] == "-1" if showAll { args = args[1:] } if len(args) > 0 { filterString = strings.Join(args, " ") a.TaskList = a.getFilteredList(filterString) } a.TaskList.Sort(todotxt.SORT_USEFULNESS_ASC) for _, v := range *a.TaskList { fmt.Println(a.getTaskString(v)) lastIdx++ } if showAll { if err := app.LoadDoneList(); err != nil { fmt.Println(a.s(ResStrErrLoadingDoneList)) fmt.Println(err.Error()) return 1 } if filterString != "" { a.DoneList = a.getFilteredList(filterString) } for _, v := range *a.DoneList { fmt.Println(a.getDoneTaskString(v)) } } return 0 } func (a *AppState) opAddTask(args []string) int { taskString := strings.Join(args, " ") if err := a.addTask(taskString); err != nil { fmt.Println("Error adding task") fmt.Println(err.Error()) return 1 } return 0 } func (a *AppState) opToggleTaskComplete(args []string) int { if len(args) == 0 { fmt.Println("No id given") return 1 } if len(args) == 0 { fmt.Println("No id given") return 1 } for _, v := range args { var id int var err error if id, err = strconv.Atoi(v); err != nil { fmt.Printf("Invalid id given: %s\n", v) return 1 } if err := a.toggleTaskComplete(id); err != nil { fmt.Println(err.Error()) return 1 } } if a.WriteList() != nil { fmt.Println(a.s(ResStrErrSavingList)) return 1 } return 0 } func (a *AppState) opArchiveTasks(args []string) int { if len(args) > 0 { for _, v := range args { var id int var task *todotxt.Task var err error if id, err = strconv.Atoi(v); err != nil { fmt.Printf("Invalid id given: %s\n", v) return 1 } if task, err = a.TaskList.GetTask(id); err != nil { fmt.Printf("Error getting task %d\n", id) return 1 } if err = a.archiveTask(id); err != nil { fmt.Printf("Error archiving task %d\n", id) return 1 } fmt.Println(a.getDoneTaskString(*task)) } } else { for _, v := range *a.TaskList { if v.Completed { if err := a.archiveTask(v.Id); err != nil { fmt.Printf("Error archiving task %d\n", v.Id) return 1 } fmt.Println(a.getDoneTaskString(v)) } } } return 0 } func (a *AppState) opPrintUsage(args []string) int { for _, v := range a.ValidOperations { for _, vv := range v { fmt.Println(" " + vv) fmt.Println("") } } return 0 }