Compare commits
3 Commits
4d9482f363
...
#7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
061006c73b
|
||
|
|
1ec5072ef4 | ||
|
|
3acff6618c |
110
bubbletea.go
110
bubbletea.go
@@ -2,8 +2,11 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"regexp"
|
||||||
|
"time"
|
||||||
|
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
|
"github.com/charmbracelet/lipgloss"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (m model) Init() tea.Cmd {
|
func (m model) Init() tea.Cmd {
|
||||||
@@ -66,15 +69,25 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
m.textinput.Reset()
|
m.textinput.Reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case "enter":
|
||||||
|
if m.addTask {
|
||||||
|
AddNewTask(&m)
|
||||||
|
m.addTask = false
|
||||||
|
m.textinput.Reset()
|
||||||
|
}
|
||||||
|
|
||||||
// The "enter" key and the spacebar (a literal space) toggle
|
// The "enter" key and the spacebar (a literal space) toggle
|
||||||
// the selected state for the item that the cursor is pointing at.
|
// the selected state for the item that the cursor is pointing at.
|
||||||
case "enter", " ":
|
case " ":
|
||||||
_, ok := m.selected[m.cursor]
|
|
||||||
if ok {
|
if !m.addTask {
|
||||||
delete(m.selected, m.cursor)
|
if m.todos[m.cursor].done {
|
||||||
} else {
|
m.todos[m.cursor].done = false
|
||||||
m.selected[m.cursor] = struct{}{}
|
} else {
|
||||||
|
m.todos[m.cursor].done = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,30 +97,68 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
return m, 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()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
t := todo{
|
||||||
|
name: taskTitle,
|
||||||
|
done: false,
|
||||||
|
startdate: doDate,
|
||||||
|
deadline: deadline,
|
||||||
|
priority: 1,
|
||||||
|
isInbox: true,
|
||||||
|
}
|
||||||
|
m.todos = append(m.todos, t)
|
||||||
|
}
|
||||||
|
|
||||||
func (m model) View() string {
|
func (m model) View() string {
|
||||||
// The header
|
// The header
|
||||||
s := ""
|
s := ""
|
||||||
currentList := []todo{}
|
currentList := []todo{}
|
||||||
|
|
||||||
// switch m.tab {
|
|
||||||
// case 0:
|
|
||||||
// s += "Inbox"
|
|
||||||
// inboxFilter := func(t todo) bool { return t.isInbox }
|
|
||||||
// currentList = filter(m.todos, inboxFilter)
|
|
||||||
// case 1:
|
|
||||||
// s += "Today"
|
|
||||||
// case 2:
|
|
||||||
// s += "Tomorrow"
|
|
||||||
// case 3:
|
|
||||||
// s += "Scheduled"
|
|
||||||
// case 4:
|
|
||||||
// s += "Anytime"
|
|
||||||
// }
|
|
||||||
|
|
||||||
s += "GOTD\n\n"
|
s += "GOTD\n\n"
|
||||||
|
|
||||||
|
switch m.tab {
|
||||||
|
case 0:
|
||||||
|
// s += "Inbox"
|
||||||
|
taskFilter := func(t todo) bool { return t.isInbox }
|
||||||
|
currentList = filter(m.todos, taskFilter)
|
||||||
|
case 1:
|
||||||
|
// s += "Today"
|
||||||
|
taskFilter := func(t todo) bool { return t.startdate == midnightToUnix() || t.deadline == midnightToUnix() }
|
||||||
|
currentList = filter(m.todos, taskFilter)
|
||||||
|
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)
|
||||||
|
case 3:
|
||||||
|
// s += "Scheduled"
|
||||||
|
taskFilter := func(t todo) bool { return t.startdate != -1 }
|
||||||
|
currentList = filter(m.todos, taskFilter)
|
||||||
|
case 4:
|
||||||
|
// s += "Anytime"
|
||||||
|
taskFilter := func(t todo) bool { return t.startdate == -1 }
|
||||||
|
currentList = filter(m.todos, taskFilter)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Iterate over our choices
|
// Iterate over our choices
|
||||||
for i, choice := range currentList {
|
for i, value := range currentList {
|
||||||
|
|
||||||
// Is the cursor pointing at this choice?
|
// Is the cursor pointing at this choice?
|
||||||
cursor := " " // no cursor
|
cursor := " " // no cursor
|
||||||
@@ -117,14 +168,21 @@ func (m model) View() string {
|
|||||||
|
|
||||||
// Is this choice selected?
|
// Is this choice selected?
|
||||||
checked := " " // not selected
|
checked := " " // not selected
|
||||||
if _, ok := m.selected[i]; ok {
|
// if _, ok := m.selected[i]; ok {
|
||||||
checked = "x" // selected!
|
// checked = "x" // selected!
|
||||||
|
// }
|
||||||
|
if value.done {
|
||||||
|
checked = "x"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderedTime := time.Unix(value.startdate, 0)
|
||||||
|
|
||||||
// Render the row
|
// Render the row
|
||||||
s += fmt.Sprintf("%s [%s] %s\n", cursor, checked, choice)
|
s += fmt.Sprintf("%s [%s] %s – %s\n", cursor, checked, value.name, renderedTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
)
|
)
|
||||||
@@ -15,6 +16,12 @@ 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" {
|
||||||
|
|||||||
8
model.go
8
model.go
@@ -7,15 +7,15 @@ import (
|
|||||||
type todo struct {
|
type todo struct {
|
||||||
name string
|
name string
|
||||||
done bool
|
done bool
|
||||||
deadline int
|
deadline int64
|
||||||
startdate int
|
startdate int64
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
type model struct {
|
type model struct {
|
||||||
todos []todo // ALL items on the to-do list
|
todos []todo // ALL items on the to-do list
|
||||||
list []todo // items currently visible on the list right now
|
// list []todo // items currently visible on the list right now
|
||||||
cursor int // which to-do list item our cursor is pointing at
|
cursor int // which to-do list item our cursor is pointing at
|
||||||
selected map[int]struct{} // which to-do items are selected
|
selected map[int]struct{} // which to-do items are selected
|
||||||
tab int // which tab is selected
|
tab int // which tab is selected
|
||||||
@@ -36,7 +36,7 @@ func initialModel() model {
|
|||||||
// Start empty
|
// Start empty
|
||||||
todos: []todo{},
|
todos: []todo{},
|
||||||
|
|
||||||
list: []todo{},
|
// list: []todo{},
|
||||||
|
|
||||||
// start on today tab
|
// start on today tab
|
||||||
// 0: inbox, 1: today, 2: tomorrow, 3: scheduled, 4: anytime
|
// 0: inbox, 1: today, 2: tomorrow, 3: scheduled, 4: anytime
|
||||||
|
|||||||
Reference in New Issue
Block a user