Compare commits

..

7 commits

Author SHA1 Message Date
Anish Lakhwara 5d1b6afb1c WIP 2024-05-26 17:19:30 -07:00
Anish Lakhwara a8babd5e99 task: format time correctly for taskNotes 2024-05-25 03:22:17 -07:00
Anish Lakhwara d2ce0cc991 create date correctly for pom file 2024-05-25 03:20:59 -07:00
Anish Lakhwara 457dd298bd task: link tags to indexs 2024-05-25 03:20:34 -07:00
Anish Lakhwara 30f6f2b7b4 feat: move init to tea.msg 2024-05-25 03:20:21 -07:00
Anish Lakhwara 98482784bc feat: createTaskNote moved to own function 2024-05-25 03:18:49 -07:00
Anish Lakhwara bb9f171579 fix: move tasks to own file 2024-05-25 02:00:57 -07:00
5 changed files with 111 additions and 64 deletions

0
editor/editor.go Normal file
View file

5
go.mod
View file

@ -7,20 +7,23 @@ require (
github.com/charmbracelet/bubbletea v0.25.0
github.com/charmbracelet/lipgloss v0.9.1
github.com/jubnzv/go-taskwarrior v0.0.0-20220111032313-0ea4f466b47c
github.com/looplab/fsm v1.0.2
github.com/mattn/go-runewidth v0.0.15
)
require (
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/rivo/uniseg v0.4.6 // indirect
github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.6.0 // indirect

6
go.sum
View file

@ -1,3 +1,5 @@
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/charmbracelet/bubbles v0.18.0 h1:PYv1A036luoBGroX6VWjQIE9Syf2Wby2oOl/39KLfy0=
@ -10,6 +12,8 @@ github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 h1:q2hJAaP1k2
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk=
github.com/jubnzv/go-taskwarrior v0.0.0-20220111032313-0ea4f466b47c h1:kJrwAIwdz2RiLmvJUW2l7tS+C5CK2DGVVSNPHuzc/4A=
github.com/jubnzv/go-taskwarrior v0.0.0-20220111032313-0ea4f466b47c/go.mod h1:B7C5T6DtQTAN6Lk0EhC9JHG/9Ny0aLIJqUych2CfZAE=
github.com/looplab/fsm v1.0.2 h1:f0kdMzr4CRpXtaKKRUxwLYJ7PirTdwrtNumeLN+mDx8=
github.com/looplab/fsm v1.0.2/go.mod h1:PmD3fFvQEIsjMEfvZdrCDZ6y8VwKTwWNjlpEr6IKPO4=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98=
@ -34,6 +38,8 @@ github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.6 h1:Sovz9sDSwbOz9tgUy8JpT+KgCkPYJEN/oYzlJiYTNLg=
github.com/rivo/uniseg v0.4.6/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f h1:MvTmaQdww/z0Q4wrYjDSCcZ78NoftLQyHBSLW/Cx79Y=
github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

101
main.go
View file

@ -2,17 +2,18 @@ package main
import (
"fmt"
table "git.sealight.xyz/aynish/poms/table"
task "git.sealight.xyz/aynish/poms/task"
timer "git.sealight.xyz/aynish/poms/timer"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"log"
"os"
"os/exec"
"strconv"
"strings"
"time"
table "git.sealight.xyz/aynish/poms/table"
task "git.sealight.xyz/aynish/poms/task"
timer "git.sealight.xyz/aynish/poms/timer"
"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/looplab/fsm"
)
var (
@ -31,22 +32,19 @@ var (
)
type model struct {
state string
FSM *fsm.FSM
taskList table.Model
activeList list.Model
timer timer.Model
}
func TasksToRows(tasks []task.Task) []table.Row {
rows := make([]table.Row, len(tasks))
for i := 0; i < len(tasks); i++ {
t := tasks[i]
rows[i] = []string{strconv.Itoa(t.Id), t.Project, strings.Join(t.Tags[:], " "), t.Description} // fmt.Sprintf("%f", t.Urgency)
}
return rows
type LoadedTasksMsg struct {
TaskList table.Model
}
func CreateTable() table.Model {
func loadTasks() tea.Msg {
var t table.Model
rows := TasksToRows(tasks)
rows := task.TasksToRows(tasks)
t = table.New(
table.WithColumns(columns),
table.WithRows(rows),
@ -68,50 +66,11 @@ func CreateTable() table.Model {
Foreground(lipgloss.Color("0")).
Background(lipgloss.Color("120"))
t.SetStyles(s)
return t
return LoadedTasksMsg{t}
}
type editorFinishedMsg struct{ err error }
func (m model) rowsToFile() []string {
var rows []string
for index, row := range m.taskList.Rows() {
if index < m.taskList.ActiveIndex() {
// get uuid
id := row[0]
uuid_byte, err := exec.Command("task", "_get", id+".uuid").Output()
if err != nil {
log.Fatal(err)
}
uuid := string(uuid_byte[:len(uuid_byte)-1])
// create task-note if it doesn't exist
note_path := "/home/anish/kitaab/vimwiki/task-notes/" + uuid + ".wiki"
if _, err := os.Stat(note_path); os.IsNotExist(err) {
f, err := os.Create(note_path)
if err != nil {
log.Fatal(err)
}
path := time.Now().Format(time.DateOnly)
tags := strings.Replace(row[2], " ", ":", -1)
tags = ":" + row[1] + ":" + tags + ":"
fmt.Fprintln(f, "%title "+row[3])
fmt.Fprintln(f, tags)
fmt.Fprintln(f, "%date "+path)
fmt.Fprintln(f, "")
f.Close()
}
// link to task-note from pom-note
rowClone := make(table.Row, len(row))
_ = copy(rowClone, row)
rowClone[3] = "[[../task-notes/" + uuid + ".wiki|" + row[3] + "]]"
rows = append(rows, strings.Join(row[1:], " - "))
}
}
return rows
}
func (m model) writeFile() string {
t := time.Now()
var path, full_path string
@ -126,17 +85,23 @@ func (m model) writeFile() string {
defer f.Close()
fmt.Fprintln(f, "%title ")
fmt.Fprintln(f, ":pom:priv:plan:")
fmt.Fprintln(f, "%date "+path)
fmt.Fprintln(f, "%date "+t.Format("2006-01-02 15:06"))
fmt.Fprintln(f, "")
rows := m.rowsToFile()
rows := task.RowsToFile(m.taskList.Rows(), m.taskList.ActiveIndex())
for _, value := range rows {
fmt.Fprintln(f, value) // print values to f, one per line
}
return full_path
}
func (m model) setActive() {
//TODO
// Create a bubbles list of active tasks to select the one to focus on during worktime
}
func (m model) openEditor() tea.Cmd {
m.setActive()
path := m.writeFile()
editor := os.Getenv("EDITOR")
if editor == "" {
@ -148,9 +113,18 @@ func (m model) openEditor() tea.Cmd {
})
}
// TODO
// This is where the data should be loaded...
func (m model) Init() tea.Cmd { return nil }
func (m model) Init() tea.Cmd {
m.FSM = fsm.NewFSM(
"taskTable",
fsm.Events{
{Name: "toEdit", Src: []string{"taskTable", "workTimer", "breakTimer"}, Dst: "editor"},
{Name: "workTime", Src: []string{"editor", "taskList"}, Dst: "workTimer"},
{Name: "breakTime", Src: []string{"workTimer", "taskList", "editor"}, Dst: "workTimer"},
},
fsm.Callbacks{},
)
return loadTasks
}
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
@ -166,6 +140,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
//top, right, bottom, left := baseStyle.GetMargin()
m.taskList.SetWidth(msg.Width - 5)
m.taskList.SetHeight(msg.Height - 5)
case LoadedTasksMsg:
m.taskList = msg.TaskList
}
m.taskList, cmd = m.taskList.Update(msg)
return m, cmd
@ -177,7 +153,6 @@ func (m model) View() string {
func main() {
var m model
m.taskList = CreateTable()
if _, err := tea.NewProgram(m).Run(); err != nil {
fmt.Println("Error running program:", err)
os.Exit(1)

View file

@ -3,8 +3,14 @@ package task
import (
"encoding/json"
"sort"
"time"
"fmt"
"strconv"
"strings"
"log"
"os"
"os/exec"
table "git.sealight.xyz/aynish/poms/table"
)
// Task representation.
@ -38,3 +44,60 @@ func GetTasks() []Task {
})
return tasks
}
func TasksToRows(tasks []Task) []table.Row {
rows := make([]table.Row, len(tasks))
for i := 0; i < len(tasks); i++ {
t := tasks[i]
rows[i] = []string{strconv.Itoa(t.Id), t.Project, strings.Join(t.Tags[:], " "), t.Description} // fmt.Sprintf("%f", t.Urgency)
}
return rows
}
func RowsToFile(taskList []table.Row, activeIndex int) []string {
var rows []string
for index, row := range taskList {
if index < activeIndex {
// get uuid
id := row[0]
uuid_byte, err := exec.Command("task", "_get", id+".uuid").Output()
if err != nil {
log.Fatal(err)
}
uuid := string(uuid_byte[:len(uuid_byte)-1])
// create task-note if it doesn't exist
note_path := "/home/anish/kitaab/vimwiki/task-notes/" + uuid + ".wiki"
if _, err := os.Stat(note_path); os.IsNotExist(err) {
CreateTaskNote(note_path, row)
}
// link to task-note from pom-note
rowClone := make(table.Row, len(row))
_ = copy(rowClone, row)
// TODO add links to indexs of EACH tag
rowClone[2] = ""
for _, tag := range strings.Split(row[2], " ") {
rowClone[2] += "[[../indexs/" + tag + ".wiki|" + tag + "]]"
}
rowClone[3] = "[[../task-notes/" + uuid + ".wiki|" + row[3] + "]]"
rows = append(rows, strings.Join(rowClone[1:], " - "))
}
}
return rows
}
func CreateTaskNote(note_path string, row table.Row) {
t := time.Now()
f, err := os.Create(note_path)
if err != nil {
log.Fatal(err)
}
tags := strings.Replace(row[2], " ", ":", -1)
tags = ":" + row[1] + ":" + tags + ":"
fmt.Fprintln(f, "%title "+row[3])
fmt.Fprintln(f, tags)
fmt.Fprintln(f, "%date "+t.Format("2006-01-02 15:06"))
fmt.Fprintln(f, "")
defer f.Close()
}