Compare commits
3 Commits
#7
...
4d9482f363
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4d9482f363
|
||
|
|
b38412a86e
|
||
|
|
254d74bdb4
|
61
bubbletea.go
61
bubbletea.go
@@ -2,11 +2,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (m model) Init() tea.Cmd {
|
func (m model) Init() tea.Cmd {
|
||||||
@@ -98,27 +95,11 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.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{
|
t := todo{
|
||||||
name: taskTitle,
|
name: m.textinput.Value(),
|
||||||
done: false,
|
done: false,
|
||||||
startdate: doDate,
|
startdate: 0,
|
||||||
deadline: deadline,
|
deadline: 0,
|
||||||
priority: 1,
|
priority: 1,
|
||||||
isInbox: true,
|
isInbox: true,
|
||||||
}
|
}
|
||||||
@@ -128,34 +109,26 @@ func AddNewTask(m *model) {
|
|||||||
func (m model) View() string {
|
func (m model) View() string {
|
||||||
// The header
|
// The header
|
||||||
s := ""
|
s := ""
|
||||||
currentList := []todo{}
|
currentList := m.todos
|
||||||
|
|
||||||
s += "GOTD\n\n"
|
s += "GOTD\n"
|
||||||
|
|
||||||
switch m.tab {
|
switch m.tab {
|
||||||
case 0:
|
case 0:
|
||||||
// s += "Inbox"
|
s += "Inbox"
|
||||||
taskFilter := func(t todo) bool { return t.isInbox }
|
// inboxFilter := func(t todo) bool { return t.isInbox }
|
||||||
currentList = filter(m.todos, taskFilter)
|
// currentList = filter(m.todos, inboxFilter)
|
||||||
case 1:
|
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:
|
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:
|
case 3:
|
||||||
// s += "Scheduled"
|
s += "Scheduled"
|
||||||
taskFilter := func(t todo) bool { return t.startdate != -1 }
|
|
||||||
currentList = filter(m.todos, taskFilter)
|
|
||||||
case 4:
|
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
|
// Iterate over our choices
|
||||||
for i, value := range currentList {
|
for i, value := range currentList {
|
||||||
@@ -175,14 +148,10 @@ func (m model) View() string {
|
|||||||
checked = "x"
|
checked = "x"
|
||||||
}
|
}
|
||||||
|
|
||||||
renderedTime := time.Unix(value.startdate, 0)
|
|
||||||
|
|
||||||
// Render the row
|
// 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
|
// render tab bar
|
||||||
for i, v := range []string{"Inbox", "Today", "Tomorrow", "Scheduled", "Anytime"} {
|
for i, v := range []string{"Inbox", "Today", "Tomorrow", "Scheduled", "Anytime"} {
|
||||||
if i == m.tab {
|
if i == m.tab {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"time"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
)
|
)
|
||||||
@@ -16,12 +15,6 @@ func filter[T any](ss []T, test func(T) bool) (ret []T) {
|
|||||||
return
|
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() {
|
func clearTerminal() {
|
||||||
var cmd *exec.Cmd
|
var cmd *exec.Cmd
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
|
|||||||
4
model.go
4
model.go
@@ -7,8 +7,8 @@ import (
|
|||||||
type todo struct {
|
type todo struct {
|
||||||
name string
|
name string
|
||||||
done bool
|
done bool
|
||||||
deadline int64
|
deadline int
|
||||||
startdate int64
|
startdate int
|
||||||
priority int // 1-4, 1 being highest priority, 4 being no priority
|
priority int // 1-4, 1 being highest priority, 4 being no priority
|
||||||
isInbox bool
|
isInbox bool
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user