|
@@ -3,9 +3,13 @@
|
|
|
package itashi
|
|
|
|
|
|
import (
|
|
|
+ "bufio"
|
|
|
"bytes"
|
|
|
"fmt"
|
|
|
"log"
|
|
|
+ "math"
|
|
|
+ "os"
|
|
|
+ "strconv"
|
|
|
"text/template"
|
|
|
"time"
|
|
|
|
|
@@ -30,8 +34,23 @@ const HEADER_TEMPLATE = `
|
|
|
{{.Time}} {{.Meridiem}} ({{.TtEod.Hours}}H, {{.TtEod.Minutes}}M -> EoD, {{.TtSun.Hours}}H, {{.TtSun.Minutes}}M -> {{.SunCycle}})
|
|
|
`
|
|
|
|
|
|
+const TASK_ITEM = `
|
|
|
+Title: {{.Title}}
|
|
|
+-------------------------
|
|
|
+{{.Desc}}
|
|
|
+
|
|
|
+Due: {{.Due}}
|
|
|
+Priority: {{.Priority}}
|
|
|
+Done?: {{.Priority}}
|
|
|
+
|
|
|
+`
|
|
|
+
|
|
|
const TIME_TO_TEMPLATE = `{{.Hours}}H, {{.Minutes}}M`
|
|
|
|
|
|
+const HOME_TEMPLATE = ``
|
|
|
+
|
|
|
+// TODO: put all templates in their own file
|
|
|
+
|
|
|
type HeaderData struct {
|
|
|
Date string
|
|
|
Season string
|
|
@@ -131,8 +150,11 @@ func (u UserImplementation) getTimeToEod(ts time.Time) TimeToSunShift {
|
|
|
}
|
|
|
out := time.Date(ts.Year(), ts.Month(), ts.Day(), 17, 0, ts.Second(), ts.Nanosecond(), ts.Location())
|
|
|
dur := time.Until(out)
|
|
|
+ hours := dur.Minutes() / 60
|
|
|
+ hours = math.Floor(hours)
|
|
|
+ minutes := (hours * 60) - dur.Minutes()
|
|
|
|
|
|
- return TimeToSunShift{Hours: int(dur.Hours()), Minutes: int(dur.Minutes())}
|
|
|
+ return TimeToSunShift{Hours: int(hours), Minutes: int(minutes)}
|
|
|
}
|
|
|
|
|
|
func (u UserImplementation) getTimeToSunShift(ts time.Time) TimeToSunShift {
|
|
@@ -181,15 +203,8 @@ type model struct {
|
|
|
|
|
|
func InitialModel() model {
|
|
|
shelf := NewFilesystemShelf(FS_SAVE_LOCATION)
|
|
|
- // shelf.AddTask(Task{Id: 1, Title: "This is a sample task", Desc: "Quick sample task that im testing the storage with",
|
|
|
- // Due: time.Now().AddDate(0, 0, 2), Done: false, Priority: 1})
|
|
|
return model{
|
|
|
- // Our to-do list is a grocery list
|
|
|
- choices: GetTaskNames(shelf.GetAll()),
|
|
|
-
|
|
|
- // A map which indicates which choices are selected. We're using
|
|
|
- // the map like a mathematical set. The keys refer to the indexes
|
|
|
- // of the `choices` slice, above.
|
|
|
+ choices: GetTaskNames(shelf.GetAll()),
|
|
|
selected: make(map[int]struct{}),
|
|
|
}
|
|
|
}
|
|
@@ -233,6 +248,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
|
} else {
|
|
|
m.selected[m.cursor] = struct{}{}
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -247,6 +263,8 @@ func (m model) View() string {
|
|
|
if err != nil {
|
|
|
log.Fatal("Couldnt parse the header template.. sorry. ", err)
|
|
|
}
|
|
|
+ shelf := NewFilesystemShelf(FS_SAVE_LOCATION)
|
|
|
+
|
|
|
s := getHeader(UserImplementation{}, tmpl)
|
|
|
|
|
|
// Iterate over our choices
|
|
@@ -261,7 +279,13 @@ func (m model) View() string {
|
|
|
// Is this choice selected?
|
|
|
checked := " " // not selected
|
|
|
if _, ok := m.selected[i]; ok {
|
|
|
+ for x := range shelf.Tasks {
|
|
|
+ if shelf.Tasks[x].Title == choice {
|
|
|
+ return shelf.RenderTask(shelf.Tasks[x])
|
|
|
+ }
|
|
|
+ }
|
|
|
checked = "x" // selected!
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// Render the row
|
|
@@ -274,3 +298,25 @@ func (m model) View() string {
|
|
|
// Send the UI for rendering
|
|
|
return s
|
|
|
}
|
|
|
+
|
|
|
+/*
|
|
|
+Add task to the shelf
|
|
|
+*/
|
|
|
+func AddTaskPrompt(shelf TaskShelf) {
|
|
|
+ task := &Task{}
|
|
|
+ var reader *bufio.Reader
|
|
|
+ reader = bufio.NewReader(os.Stdout)
|
|
|
+ fmt.Print("Enter Task Title: ")
|
|
|
+ task.Title, _ = reader.ReadString('\n')
|
|
|
+ fmt.Print("Task description: ")
|
|
|
+ task.Desc, _ = reader.ReadString('\n')
|
|
|
+ fmt.Print("Priority: ")
|
|
|
+ priority, _ := reader.ReadString('\n')
|
|
|
+ pri, err := strconv.Atoi(priority)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Print("non-real number sry\n")
|
|
|
+ }
|
|
|
+ task.Priority = pri
|
|
|
+
|
|
|
+ shelf.AddTask(*task)
|
|
|
+}
|