Compare commits

..

1 Commits

Author SHA1 Message Date
june
254d74bdb4 Begin working on new task feature 2025-03-10 16:05:12 +13:00
3 changed files with 25 additions and 69 deletions

View File

@@ -2,11 +2,8 @@ package main
import (
"fmt"
"regexp"
"time"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
tea "github.com/charmbracelet/bubbletea"
)
func (m model) Init() tea.Cmd {
@@ -71,7 +68,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case "enter":
if m.addTask {
AddNewTask(&m)
AddNewTask(m)
m.addTask = false
m.textinput.Reset()
}
@@ -79,16 +76,13 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// The "enter" key and the spacebar (a literal space) toggle
// the selected state for the item that the cursor is pointing at.
case " ":
if !m.addTask {
if m.todos[m.cursor].done {
m.todos[m.cursor].done = false
_, ok := m.selected[m.cursor]
if ok {
delete(m.selected, m.cursor)
} else {
m.todos[m.cursor].done = true
m.selected[m.cursor] = struct{}{}
}
}
}
}
@@ -97,28 +91,12 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, cmd
}
func AddNewTask(m *model) {
taskTitle := m.textinput.Value()
// parse date in title
var doDate int64 = -1
var deadline int64 = -1
reDate := regexp.MustCompile("\\d{1,2}/\\d{1,2}")
date := reDate.FindStringSubmatch(taskTitle)
if len(date) > 0 {
// what the fuck Go
date, _ := time.Parse("02/01/2006", "10/03/2025")
doDate = date.Unix()
}
func AddNewTask(m model) {
t := todo{
name: taskTitle,
name: m.textinput.Value(),
done: false,
startdate: doDate,
deadline: deadline,
startdate: 0,
deadline: 0,
priority: 1,
isInbox: true,
}
@@ -130,32 +108,24 @@ func (m model) View() string {
s := ""
currentList := []todo{}
s += "GOTD\n\n"
s += "GOTD\n"
switch m.tab {
case 0:
// s += "Inbox"
taskFilter := func(t todo) bool { return t.isInbox }
currentList = filter(m.todos, taskFilter)
s += "Inbox"
inboxFilter := func(t todo) bool { return t.isInbox }
currentList = filter(m.todos, inboxFilter)
case 1:
// s += "Today"
taskFilter := func(t todo) bool { return t.startdate == midnightToUnix() || t.deadline == midnightToUnix() }
currentList = filter(m.todos, taskFilter)
s += "Today"
case 2:
// s += "Tomorrow"
// 86400 seconds in 24h, add it on to today's midnight for tomorrow's midnight
taskFilter := func(t todo) bool { return t.startdate == midnightToUnix() + 86400 || t.deadline == midnightToUnix() + 86400}
currentList = filter(m.todos, taskFilter)
s += "Tomorrow"
case 3:
// s += "Scheduled"
taskFilter := func(t todo) bool { return t.startdate != -1 }
currentList = filter(m.todos, taskFilter)
s += "Scheduled"
case 4:
// s += "Anytime"
taskFilter := func(t todo) bool { return t.startdate == -1 }
currentList = filter(m.todos, taskFilter)
s += "Anytime"
}
s += "\n\n"
// Iterate over our choices
for i, value := range currentList {
@@ -168,21 +138,14 @@ func (m model) View() string {
// Is this choice selected?
checked := " " // not selected
// if _, ok := m.selected[i]; ok {
// checked = "x" // selected!
// }
if value.done {
checked = "x"
if _, ok := m.selected[i]; ok {
checked = "x" // selected!
}
renderedTime := time.Unix(value.startdate, 0)
// Render the row
s += fmt.Sprintf("%s [%s] %s %s\n", cursor, checked, value.name, renderedTime)
s += fmt.Sprintf("%s [%s] %s\n", cursor, checked, value)
}
s += "\n\n"
// render tab bar
for i, v := range []string{"Inbox", "Today", "Tomorrow", "Scheduled", "Anytime"} {
if i == m.tab {

View File

@@ -2,7 +2,6 @@ package main
import (
"os"
"time"
"os/exec"
"runtime"
)
@@ -16,12 +15,6 @@ func filter[T any](ss []T, test func(T) bool) (ret []T) {
return
}
func midnightToUnix() int64 {
now := time.Now()
midnight := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
return midnight.Unix()
}
func clearTerminal() {
var cmd *exec.Cmd
if runtime.GOOS == "windows" {

View File

@@ -7,8 +7,8 @@ import (
type todo struct {
name string
done bool
deadline int64
startdate int64
deadline int
startdate int
priority int // 1-4, 1 being highest priority, 4 being no priority
isInbox bool
}