all repos — todo.txt-go @ 601f4a83a9da7611413da0b9ac67f720ee77b709

CLI tool for todo.txt files written in Go

feat: :sparkles: Add task edition
Tim Izzo tim@octree.ch
Sat, 12 Apr 2025 17:54:31 +0200
commit

601f4a83a9da7611413da0b9ac67f720ee77b709

parent

79fc5d605316916243adc3f0e252a2ec5a1a314e

3 files changed, 40 insertions(+), 7 deletions(-)

jump to
M README.mdREADME.md

@@ -4,7 +4,7 @@ ## TODO

- [x] Use _todo.txt_ file targeted by todo-txt.sh config - [x] Implement archive mecanism -- [ ] Allow task edition +- [x] Allow task edition - [x] Allow to remove priority on task - [ ] Circular navigation on tasks
M keymap.gokeymap.go

@@ -12,6 +12,7 @@ Quit key.Binding

Check key.Binding Clean key.Binding Add key.Binding + Edit key.Binding SortByPriority key.Binding SortByDate key.Binding }

@@ -35,11 +36,11 @@

var keys = keyMap{ Up: key.NewBinding( key.WithKeys("up", "k"), - key.WithHelp("↑/k", "Move up"), + key.WithHelp("↑|k", "Move up"), ), Down: key.NewBinding( key.WithKeys("down", "j"), - key.WithHelp("↓/j", "Move down"), + key.WithHelp("↓|j", "Move down"), ), Priority: key.NewBinding( key.WithKeys("a", "b", "c", "d"),

@@ -53,6 +54,10 @@ Add: key.NewBinding(

key.WithKeys("A", "+"), key.WithHelp("A|+", "Add new task"), ), + Edit: key.NewBinding( + key.WithKeys("e", "enter"), + key.WithHelp("e|Enter", "Edit task"), + ), SortByPriority: key.NewBinding( key.WithKeys("p"), key.WithHelp("p", "Sort by priority"),

@@ -66,7 +71,7 @@ key.WithKeys("?"),

key.WithHelp("?", "More help"), ), Check: key.NewBinding( - key.WithKeys(" ", "enter"), + key.WithKeys(" ", "x"), key.WithHelp("space", "Check task"), ), Clean: key.NewBinding(
M main.gomain.go

@@ -18,6 +18,7 @@

const ( List InterfaceState = iota Add + Edit ) type model struct {

@@ -177,6 +178,10 @@ // Interface

case key.Matches(msg, m.keys.Add): m.interfaceState = Add + case key.Matches(msg, m.keys.Edit): + m.textInput.SetValue(m.tasks[m.cursor].Original) + m.interfaceState = Edit + case key.Matches(msg, m.keys.Quit): m.SaveTasks() return m, tea.Quit

@@ -191,7 +196,7 @@

case Add: switch msg.Type { case tea.KeyCtrlC, tea.KeyEsc: - return m, tea.Quit + m.interfaceState = List case tea.KeyEnter: inputValue := m.textInput.Value() if inputValue != "" {

@@ -207,7 +212,26 @@ m.textInput, cmd = m.textInput.Update(msg)

return m, cmd + case Edit: + switch msg.Type { + case tea.KeyCtrlC, tea.KeyEsc: + m.interfaceState = List + + case tea.KeyEnter: + inputValue := m.textInput.Value() + if inputValue != "" { + editedTask, _ := todo.ParseTask(inputValue) + m.tasks[m.cursor] = *editedTask + } + m.textInput.Reset() + m.interfaceState = List + } + + m.textInput, cmd = m.textInput.Update(msg) + + return m, cmd } + } return m, nil

@@ -241,8 +265,12 @@

output += "\n" output += m.help.View(m.keys) case Add: - output += fmt.Sprintf("Nouvelle tâche:\n\n%s", m.textInput.View()) - output += "\n\n Press ESC to quit.\n" + output += fmt.Sprintf("New task:\n\n%s", m.textInput.View()) + output += "\n\n Press ESC to go back.\n" + + case Edit: + output += fmt.Sprintf("Edit task:\n\n%s", m.textInput.View()) + output += "\n\n Press ESC to go back.\n" } return output