Compare commits

..

3 Commits

Author SHA1 Message Date
june
061006c73b added some maybe functional date parsing for now :3 2025-03-10 21:58:36 +13:00
june
1ec5072ef4 Tasks should be filtered into their specific areas (#5)
All inbox tasks should remain in the inbox. all tasks with a start/deadline time of today should be in today. Any task that does have a start date should be in scheduled. All tasks that do not have a start date should be in Anytime.

Fixes #1
Co-authored-by: june <juniper@breadone.xyz>
Co-committed-by: june <juniper@breadone.xyz>
2025-03-10 18:42:06 +13:00
june
3acff6618c Add New Task from Keybind (#3)
press n to add new task, type in title, then press enter to save
Co-authored-by: june <juniper@breadone.xyz>
Co-committed-by: june <juniper@breadone.xyz>
2025-03-10 17:50:38 +13:00
3 changed files with 69 additions and 25 deletions

View File

@@ -2,8 +2,11 @@ package main
import (
"fmt"
"github.com/charmbracelet/lipgloss"
"regexp"
"time"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
func (m model) Init() tea.Cmd {
@@ -68,7 +71,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()
}
@@ -76,13 +79,16 @@ 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 " ":
_, ok := m.selected[m.cursor]
if ok {
delete(m.selected, m.cursor)
if !m.addTask {
if m.todos[m.cursor].done {
m.todos[m.cursor].done = false
} else {
m.selected[m.cursor] = struct{}{}
m.todos[m.cursor].done = true
}
}
}
}
@@ -91,12 +97,28 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, cmd
}
func AddNewTask(m model) {
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()
}
t := todo{
name: m.textinput.Value(),
name: taskTitle,
done: false,
startdate: 0,
deadline: 0,
startdate: doDate,
deadline: deadline,
priority: 1,
isInbox: true,
}
@@ -108,24 +130,32 @@ func (m model) View() string {
s := ""
currentList := []todo{}
s += "GOTD\n"
s += "GOTD\n\n"
switch m.tab {
case 0:
s += "Inbox"
inboxFilter := func(t todo) bool { return t.isInbox }
currentList = filter(m.todos, inboxFilter)
// s += "Inbox"
taskFilter := func(t todo) bool { return t.isInbox }
currentList = filter(m.todos, taskFilter)
case 1:
s += "Today"
// s += "Today"
taskFilter := func(t todo) bool { return t.startdate == midnightToUnix() || t.deadline == midnightToUnix() }
currentList = filter(m.todos, taskFilter)
case 2:
s += "Tomorrow"
// 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)
case 3:
s += "Scheduled"
// s += "Scheduled"
taskFilter := func(t todo) bool { return t.startdate != -1 }
currentList = filter(m.todos, taskFilter)
case 4:
s += "Anytime"
// s += "Anytime"
taskFilter := func(t todo) bool { return t.startdate == -1 }
currentList = filter(m.todos, taskFilter)
}
s += "\n\n"
// Iterate over our choices
for i, value := range currentList {
@@ -138,14 +168,21 @@ func (m model) View() string {
// Is this choice selected?
checked := " " // not selected
if _, ok := m.selected[i]; ok {
checked = "x" // selected!
// if _, ok := m.selected[i]; ok {
// checked = "x" // selected!
// }
if value.done {
checked = "x"
}
renderedTime := time.Unix(value.startdate, 0)
// Render the row
s += fmt.Sprintf("%s [%s] %s\n", cursor, checked, value)
s += fmt.Sprintf("%s [%s] %s %s\n", cursor, checked, value.name, renderedTime)
}
s += "\n\n"
// render tab bar
for i, v := range []string{"Inbox", "Today", "Tomorrow", "Scheduled", "Anytime"} {
if i == m.tab {

View File

@@ -2,6 +2,7 @@ package main
import (
"os"
"time"
"os/exec"
"runtime"
)
@@ -15,6 +16,12 @@ 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 int
startdate int
deadline int64
startdate int64
priority int // 1-4, 1 being highest priority, 4 being no priority
isInbox bool
}