summaryrefslogtreecommitdiff
path: root/internal/ui/table.go
diff options
context:
space:
mode:
authorPaul Bütow <1224732+snonux@users.noreply.github.com>2025-06-20 18:33:23 +0300
committerGitHub <noreply@github.com>2025-06-20 18:33:23 +0300
commitfd6ac6bf1c2269093ba9fa0b20365a31d12a7bfa (patch)
tree3d127d6205b9c6b49197a0a45fd51269ace6fed8 /internal/ui/table.go
parent20417e3024916a23a0378f72c1336ccbb56f0bae (diff)
parent4f073ba6a8cbd95368b8e0e7b9340b04448f0b4d (diff)
Merge pull request #24 from snonux/codex/add--a--hotkey-for-task-annotation
Add annotation hotkey
Diffstat (limited to 'internal/ui/table.go')
-rw-r--r--internal/ui/table.go45
1 files changed, 44 insertions, 1 deletions
diff --git a/internal/ui/table.go b/internal/ui/table.go
index 51bd9e4..a3f6581 100644
--- a/internal/ui/table.go
+++ b/internal/ui/table.go
@@ -8,6 +8,7 @@ import (
"github.com/charmbracelet/x/ansi"
+ "github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
@@ -20,6 +21,10 @@ type Model struct {
tbl atable.Model
showHelp bool
+ annotating bool
+ annotateID int
+ annotateInput textinput.Model
+
filter string
tasks []task.Task
@@ -41,6 +46,8 @@ func editCmd(id int) tea.Cmd {
// New creates a new UI model with the provided rows.
func New(filter string) (Model, error) {
m := Model{filter: filter}
+ m.annotateInput = textinput.New()
+ m.annotateInput.Prompt = "annotation: "
if err := m.reload(); err != nil {
return Model{}, err
@@ -119,6 +126,23 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.reload()
return m, nil
case tea.KeyMsg:
+ if m.annotating {
+ switch msg.Type {
+ case tea.KeyEnter:
+ task.Annotate(m.annotateID, m.annotateInput.Value())
+ m.annotating = false
+ m.annotateInput.Blur()
+ m.reload()
+ return m, nil
+ case tea.KeyEsc:
+ m.annotating = false
+ m.annotateInput.Blur()
+ return m, nil
+ }
+ var cmd tea.Cmd
+ m.annotateInput, cmd = m.annotateInput.Update(msg)
+ return m, cmd
+ }
switch msg.String() {
case "?":
m.showHelp = true
@@ -155,6 +179,17 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.reload()
}
}
+ case "a":
+ if row := m.tbl.SelectedRow(); row != nil {
+ idStr := ansi.Strip(row[0])
+ if id, err := strconv.Atoi(idStr); err == nil {
+ m.annotateID = id
+ m.annotating = true
+ m.annotateInput.SetValue("")
+ m.annotateInput.Focus()
+ return m, nil
+ }
+ }
}
}
@@ -174,14 +209,22 @@ func (m Model) View() string {
m.tbl.HelpView(),
"E: edit task",
"s: toggle start/stop",
+ "a: annotate task",
"q: quit",
"?: help", // show help toggle line
)
}
- return lipgloss.JoinVertical(lipgloss.Left,
+ view := lipgloss.JoinVertical(lipgloss.Left,
m.tbl.View(),
m.statusLine(),
)
+ if m.annotating {
+ view = lipgloss.JoinVertical(lipgloss.Left,
+ view,
+ m.annotateInput.View(),
+ )
+ }
+ return view
}
func (m Model) statusLine() string {