Browse Source

views on it look pretty alright

aeth 1 month ago
parent
commit
5edd84855f
2 changed files with 38 additions and 13 deletions
  1. 18 0
      pkg/savestate.go
  2. 20 13
      pkg/userinterface.go

+ 18 - 0
pkg/savestate.go

@@ -8,6 +8,8 @@ import (
 	"strings"
 	"text/template"
 	"time"
+
+	tea "github.com/charmbracelet/bubbletea"
 )
 
 const SHELF_LINE_DELIM = "\n----    ----    ----    ----\n"
@@ -25,6 +27,20 @@ type Task struct {
 	Priority int
 }
 
+// lets make Task implement the tea.Model interface
+func (t Task) Init() tea.Cmd {
+	return nil
+
+}
+
+func (t Task) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
+	return t, nil
+}
+
+func (t Task) View() string {
+	return ""
+}
+
 type TaskShelf interface {
 	// Modify the due date of an existing task
 	ModifyDue(id int, due time.Time)
@@ -44,6 +60,8 @@ type TaskShelf interface {
 	AddTask(t Task)
 	// Retrieve all tasks in the shelf
 	GetAll() []Task
+	// Render a task to a task template
+	RenderTask(task Task) string
 }
 
 /*

+ 20 - 13
pkg/userinterface.go

@@ -35,20 +35,19 @@ const HEADER_TEMPLATE = `
 `
 
 const TASK_ITEM = `
-Title: {{.Title}}
--------------------------
-{{.Desc}}
-
-Due: {{.Due}}
-Priority: {{.Priority}}
-Done?: {{.Priority}}
-
++------------------------------------
+|  
+|  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 {
@@ -152,7 +151,7 @@ func (u UserImplementation) getTimeToEod(ts time.Time) TimeToSunShift {
 	dur := time.Until(out)
 	hours := dur.Minutes() / 60
 	hours = math.Floor(hours)
-	minutes := (hours * 60) - dur.Minutes()
+	minutes := dur.Minutes() - (hours * 60)
 
 	return TimeToSunShift{Hours: int(hours), Minutes: int(minutes)}
 }
@@ -165,7 +164,13 @@ func (u UserImplementation) getSunCycle(ts time.Time) string {
 	return "☼"
 }
 func (u UserImplementation) getTime(ts time.Time) string {
-	return fmt.Sprintf("%v:%v", ts.Hour(), ts.Minute())
+	var hour int
+	if ts.Hour() == 0 {
+		hour = 12
+	} else {
+		hour = ts.Hour()
+	}
+	return fmt.Sprintf("%v:%v", hour, ts.Minute())
 }
 func (u UserImplementation) getDate(ts time.Time) string {
 	return fmt.Sprintf("%s %v, %v", ts.Month().String(), ts.Day(), ts.Year())
@@ -277,11 +282,12 @@ func (m model) View() string {
 		}
 
 		// Is this choice selected?
+		var taskrender string
 		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])
+					taskrender = shelf.RenderTask(shelf.Tasks[x])
 				}
 			}
 			checked = "x" // selected!
@@ -290,6 +296,7 @@ func (m model) View() string {
 
 		// Render the row
 		s += fmt.Sprintf("%s [%s] %s\n", cursor, checked, choice)
+		s += taskrender
 	}
 
 	// The footer