From 74fc699fabd50e3072d81242a9ade62ef8af34bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20B=C3=BCtow?= <1224732+snonux@users.noreply.github.com> Date: Sun, 22 Jun 2025 14:04:53 +0300 Subject: Fix task modification marking done and swap hotkeys --- internal/ui/table.go | 61 ++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 30 deletions(-) (limited to 'internal/ui/table.go') diff --git a/internal/ui/table.go b/internal/ui/table.go index 3d26f41..a5c3e8e 100644 --- a/internal/ui/table.go +++ b/internal/ui/table.go @@ -78,10 +78,11 @@ type Model struct { editID int - blinkID int - blinkRow int - blinkOn bool - blinkCount int + blinkID int + blinkRow int + blinkOn bool + blinkCount int + blinkMarkDone bool cellExpanded bool @@ -124,8 +125,9 @@ func blinkCmd() tea.Cmd { return tea.Tick(blinkInterval, func(time.Time) tea.Msg { return blinkMsg{} }) } -func (m *Model) startBlink(id int) tea.Cmd { +func (m *Model) startBlink(id int, markDone bool) tea.Cmd { m.blinkID = id + m.blinkMarkDone = markDone m.blinkRow = -1 for i, tsk := range m.tasks { if tsk.ID == id { @@ -264,7 +266,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { // Ignore any error and reload tasks once editing completes. _ = msg.err m.reload() - cmd := m.startBlink(m.editID) + cmd := m.startBlink(m.editID, false) m.editID = 0 return m, cmd case blinkMsg: @@ -274,16 +276,20 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.updateBlinkRow() if m.blinkCount >= blinkCycles { id := m.blinkID + mark := m.blinkMarkDone m.blinkID = 0 m.blinkOn = false m.blinkCount = 0 - for _, tsk := range m.tasks { - if tsk.ID == id { - m.undoStack = append(m.undoStack, tsk.UUID) - break + m.blinkMarkDone = false + if mark { + for _, tsk := range m.tasks { + if tsk.ID == id { + m.undoStack = append(m.undoStack, tsk.UUID) + break + } } + task.Done(id) } - task.Done(id) m.reload() return m, nil } @@ -303,7 +309,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.annotating = false m.annotateInput.Blur() m.reload() - cmd := m.startBlink(m.annotateID) + cmd := m.startBlink(m.annotateID, false) m.updateTableHeight() return m, cmd case tea.KeyEsc: @@ -324,7 +330,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.descEditing = false m.descInput.Blur() m.reload() - cmd := m.startBlink(m.descID) + cmd := m.startBlink(m.descID, false) m.updateTableHeight() return m, cmd case tea.KeyEsc: @@ -365,7 +371,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.tagsEditing = false m.tagsInput.Blur() m.reload() - cmd := m.startBlink(m.tagsID) + cmd := m.startBlink(m.tagsID, false) m.updateTableHeight() return m, cmd case tea.KeyEsc: @@ -384,7 +390,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { task.SetDueDate(m.dueID, m.dueDate.Format("2006-01-02")) m.dueEditing = false m.reload() - cmd := m.startBlink(m.dueID) + cmd := m.startBlink(m.dueID, false) m.updateTableHeight() return m, cmd case tea.KeyEsc: @@ -411,7 +417,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.recurEditing = false m.recurInput.Blur() m.reload() - cmd := m.startBlink(m.recurID) + cmd := m.startBlink(m.recurID, false) m.updateTableHeight() return m, cmd case tea.KeyEsc: @@ -430,7 +436,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { task.SetPriority(m.priorityID, priorityOptions[m.priorityIndex]) m.prioritySelecting = false m.reload() - cmd := m.startBlink(m.priorityID) + cmd := m.startBlink(m.priorityID, false) m.updateTableHeight() return m, cmd case tea.KeyEsc: @@ -547,20 +553,15 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { task.Start(id) } m.reload() - cmd := m.startBlink(id) + cmd := m.startBlink(id, false) return m, cmd } } - case "D": + case "d": if row := m.tbl.SelectedRow(); row != nil { idStr := ansi.Strip(row[1]) if id, err := strconv.Atoi(idStr); err == nil { - m.blinkID = id - m.blinkRow = m.tbl.Cursor() - m.blinkOn = true - m.blinkCount = 0 - m.updateBlinkRow() - return m, blinkCmd() + return m, m.startBlink(id, true) } } case "U": @@ -576,10 +577,10 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { break } } - cmd := m.startBlink(id) + cmd := m.startBlink(id, false) return m, cmd } - case "d": + case "D": if row := m.tbl.SelectedRow(); row != nil { idStr := ansi.Strip(row[1]) if id, err := strconv.Atoi(idStr); err == nil { @@ -598,7 +599,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { due := time.Now().AddDate(0, 0, days).Format("2006-01-02") task.SetDueDate(id, due) m.reload() - cmd := m.startBlink(id) + cmd := m.startBlink(id, false) return m, cmd } } @@ -801,9 +802,9 @@ func (m Model) View() string { "enter/i: edit or expand cell", "E: edit task", "s: toggle start/stop", - "D: mark task done", + "d: mark task done", "U: undo done", - "d: set due date", + "D: set due date", "r: random due date", "R: edit recurrence", "a: annotate task", -- cgit v1.2.3 From e42bb79ed74cb975db0c4b8128b9014f0f6acf33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20B=C3=BCtow?= <1224732+snonux@users.noreply.github.com> Date: Sun, 22 Jun 2025 14:16:15 +0300 Subject: Add task creation hotkey --- internal/ui/table.go | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) (limited to 'internal/ui/table.go') diff --git a/internal/ui/table.go b/internal/ui/table.go index a5c3e8e..482d89e 100644 --- a/internal/ui/table.go +++ b/internal/ui/table.go @@ -61,6 +61,9 @@ type Model struct { filterEditing bool filterInput textinput.Model + addingTask bool + addInput textinput.Model + searching bool searchInput textinput.Model searchRegex *regexp.Regexp @@ -161,6 +164,9 @@ func New(filters []string) (Model, error) { m.filterInput = textinput.New() m.filterInput.Prompt = "filter: " + m.addInput = textinput.New() + m.addInput.Prompt = "add: " + m.defaultTheme = DefaultTheme() m.theme = m.defaultTheme @@ -471,6 +477,46 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.filterInput, cmd = m.filterInput.Update(msg) return m, cmd } + if m.addingTask { + switch msg.Type { + case tea.KeyEnter: + oldIDs := make(map[int]struct{}) + for _, tsk := range m.tasks { + oldIDs[tsk.ID] = struct{}{} + } + task.Add(m.addInput.Value(), nil) + m.addingTask = false + m.addInput.Blur() + m.reload() + var newID int + row := -1 + for i, tsk := range m.tasks { + if _, ok := oldIDs[tsk.ID]; !ok { + newID = tsk.ID + row = i + break + } + } + m.updateTableHeight() + if row >= 0 { + prevRow := m.tbl.Cursor() + prevCol := m.tbl.ColumnCursor() + m.tbl.SetCursor(row) + m.tbl.SetColumnCursor(7) + m.updateSelectionHighlight(prevRow, m.tbl.Cursor(), prevCol, m.tbl.ColumnCursor()) + return m, m.startBlink(newID, false) + } + return m, nil + case tea.KeyEsc: + m.addingTask = false + m.addInput.Blur() + m.updateTableHeight() + return m, nil + } + var cmd tea.Cmd + m.addInput, cmd = m.addInput.Update(msg) + return m, cmd + } if m.searching { switch msg.Type { case tea.KeyEnter: @@ -658,6 +704,12 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.filterInput.Focus() m.updateTableHeight() return m, nil + case "+": + m.addingTask = true + m.addInput.SetValue("") + m.addInput.Focus() + m.updateTableHeight() + return m, nil case "t": if row := m.tbl.SelectedRow(); row != nil { idStr := ansi.Strip(row[1]) @@ -801,6 +853,7 @@ func (m Model) View() string { m.tbl.HelpView(), "enter/i: edit or expand cell", "E: edit task", + "+: add task", "s: toggle start/stop", "d: mark task done", "U: undo done", @@ -875,6 +928,12 @@ func (m Model) View() string { m.filterInput.View(), ) } + if m.addingTask { + view = lipgloss.JoinVertical(lipgloss.Left, + view, + m.addInput.View(), + ) + } if m.searching { view = lipgloss.JoinVertical(lipgloss.Left, view, @@ -1188,7 +1247,7 @@ func (m *Model) updateTableHeight() { if m.cellExpanded { h-- } - if m.annotating || m.dueEditing || m.prioritySelecting || m.searching || m.descEditing || m.tagsEditing || m.recurEditing || m.filterEditing { + if m.annotating || m.dueEditing || m.prioritySelecting || m.searching || m.descEditing || m.tagsEditing || m.recurEditing || m.filterEditing || m.addingTask { h-- } if h < 1 { -- cgit v1.2.3 From dc1a6e83669dd22be4542833970d3251741ba1f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20B=C3=BCtow?= <1224732+snonux@users.noreply.github.com> Date: Sun, 22 Jun 2025 16:39:56 +0300 Subject: Fix add task hotkey --- internal/ui/table.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'internal/ui/table.go') diff --git a/internal/ui/table.go b/internal/ui/table.go index 482d89e..c3e1748 100644 --- a/internal/ui/table.go +++ b/internal/ui/table.go @@ -484,7 +484,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { for _, tsk := range m.tasks { oldIDs[tsk.ID] = struct{}{} } - task.Add(m.addInput.Value(), nil) + task.AddLine(m.addInput.Value()) m.addingTask = false m.addInput.Blur() m.reload() -- cgit v1.2.3 From b140c36cd8bb3d20c7211fe672b9d5674c9f0d3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20B=C3=BCtow?= <1224732+snonux@users.noreply.github.com> Date: Sun, 22 Jun 2025 16:50:46 +0300 Subject: Add generic task command hotkey --- internal/ui/table.go | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) (limited to 'internal/ui/table.go') diff --git a/internal/ui/table.go b/internal/ui/table.go index c3e1748..480936c 100644 --- a/internal/ui/table.go +++ b/internal/ui/table.go @@ -64,6 +64,9 @@ type Model struct { addingTask bool addInput textinput.Model + runningTask bool + taskInput textinput.Model + searching bool searchInput textinput.Model searchRegex *regexp.Regexp @@ -167,6 +170,9 @@ func New(filters []string) (Model, error) { m.addInput = textinput.New() m.addInput.Prompt = "add: " + m.taskInput = textinput.New() + m.taskInput.Prompt = "task: " + m.defaultTheme = DefaultTheme() m.theme = m.defaultTheme @@ -517,6 +523,46 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.addInput, cmd = m.addInput.Update(msg) return m, cmd } + if m.runningTask { + switch msg.Type { + case tea.KeyEnter: + oldIDs := make(map[int]struct{}) + for _, tsk := range m.tasks { + oldIDs[tsk.ID] = struct{}{} + } + task.RunLine(m.taskInput.Value()) + m.runningTask = false + m.taskInput.Blur() + m.reload() + var newID int + row := -1 + for i, tsk := range m.tasks { + if _, ok := oldIDs[tsk.ID]; !ok { + newID = tsk.ID + row = i + break + } + } + m.updateTableHeight() + if row >= 0 { + prevRow := m.tbl.Cursor() + prevCol := m.tbl.ColumnCursor() + m.tbl.SetCursor(row) + m.tbl.SetColumnCursor(7) + m.updateSelectionHighlight(prevRow, m.tbl.Cursor(), prevCol, m.tbl.ColumnCursor()) + return m, m.startBlink(newID, false) + } + return m, nil + case tea.KeyEsc: + m.runningTask = false + m.taskInput.Blur() + m.updateTableHeight() + return m, nil + } + var cmd tea.Cmd + m.taskInput, cmd = m.taskInput.Update(msg) + return m, cmd + } if m.searching { switch msg.Type { case tea.KeyEnter: @@ -710,6 +756,12 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.addInput.Focus() m.updateTableHeight() return m, nil + case "T": + m.runningTask = true + m.taskInput.SetValue("") + m.taskInput.Focus() + m.updateTableHeight() + return m, nil case "t": if row := m.tbl.SelectedRow(); row != nil { idStr := ansi.Strip(row[1]) @@ -853,6 +905,7 @@ func (m Model) View() string { m.tbl.HelpView(), "enter/i: edit or expand cell", "E: edit task", + "T: run task command", "+: add task", "s: toggle start/stop", "d: mark task done", @@ -934,6 +987,12 @@ func (m Model) View() string { m.addInput.View(), ) } + if m.runningTask { + view = lipgloss.JoinVertical(lipgloss.Left, + view, + m.taskInput.View(), + ) + } if m.searching { view = lipgloss.JoinVertical(lipgloss.Left, view, @@ -1247,7 +1306,7 @@ func (m *Model) updateTableHeight() { if m.cellExpanded { h-- } - if m.annotating || m.dueEditing || m.prioritySelecting || m.searching || m.descEditing || m.tagsEditing || m.recurEditing || m.filterEditing || m.addingTask { + if m.annotating || m.dueEditing || m.prioritySelecting || m.searching || m.descEditing || m.tagsEditing || m.recurEditing || m.filterEditing || m.addingTask || m.runningTask { h-- } if h < 1 { -- cgit v1.2.3 From 8a83fbf747bda27f5859ad84c2f20a9afb753e39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20B=C3=BCtow?= <1224732+snonux@users.noreply.github.com> Date: Sun, 22 Jun 2025 16:58:00 +0300 Subject: Clean up unused RunArgs comments --- internal/ui/table.go | 61 +--------------------------------------------------- 1 file changed, 1 insertion(+), 60 deletions(-) (limited to 'internal/ui/table.go') diff --git a/internal/ui/table.go b/internal/ui/table.go index 480936c..c3e1748 100644 --- a/internal/ui/table.go +++ b/internal/ui/table.go @@ -64,9 +64,6 @@ type Model struct { addingTask bool addInput textinput.Model - runningTask bool - taskInput textinput.Model - searching bool searchInput textinput.Model searchRegex *regexp.Regexp @@ -170,9 +167,6 @@ func New(filters []string) (Model, error) { m.addInput = textinput.New() m.addInput.Prompt = "add: " - m.taskInput = textinput.New() - m.taskInput.Prompt = "task: " - m.defaultTheme = DefaultTheme() m.theme = m.defaultTheme @@ -523,46 +517,6 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.addInput, cmd = m.addInput.Update(msg) return m, cmd } - if m.runningTask { - switch msg.Type { - case tea.KeyEnter: - oldIDs := make(map[int]struct{}) - for _, tsk := range m.tasks { - oldIDs[tsk.ID] = struct{}{} - } - task.RunLine(m.taskInput.Value()) - m.runningTask = false - m.taskInput.Blur() - m.reload() - var newID int - row := -1 - for i, tsk := range m.tasks { - if _, ok := oldIDs[tsk.ID]; !ok { - newID = tsk.ID - row = i - break - } - } - m.updateTableHeight() - if row >= 0 { - prevRow := m.tbl.Cursor() - prevCol := m.tbl.ColumnCursor() - m.tbl.SetCursor(row) - m.tbl.SetColumnCursor(7) - m.updateSelectionHighlight(prevRow, m.tbl.Cursor(), prevCol, m.tbl.ColumnCursor()) - return m, m.startBlink(newID, false) - } - return m, nil - case tea.KeyEsc: - m.runningTask = false - m.taskInput.Blur() - m.updateTableHeight() - return m, nil - } - var cmd tea.Cmd - m.taskInput, cmd = m.taskInput.Update(msg) - return m, cmd - } if m.searching { switch msg.Type { case tea.KeyEnter: @@ -756,12 +710,6 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.addInput.Focus() m.updateTableHeight() return m, nil - case "T": - m.runningTask = true - m.taskInput.SetValue("") - m.taskInput.Focus() - m.updateTableHeight() - return m, nil case "t": if row := m.tbl.SelectedRow(); row != nil { idStr := ansi.Strip(row[1]) @@ -905,7 +853,6 @@ func (m Model) View() string { m.tbl.HelpView(), "enter/i: edit or expand cell", "E: edit task", - "T: run task command", "+: add task", "s: toggle start/stop", "d: mark task done", @@ -987,12 +934,6 @@ func (m Model) View() string { m.addInput.View(), ) } - if m.runningTask { - view = lipgloss.JoinVertical(lipgloss.Left, - view, - m.taskInput.View(), - ) - } if m.searching { view = lipgloss.JoinVertical(lipgloss.Left, view, @@ -1306,7 +1247,7 @@ func (m *Model) updateTableHeight() { if m.cellExpanded { h-- } - if m.annotating || m.dueEditing || m.prioritySelecting || m.searching || m.descEditing || m.tagsEditing || m.recurEditing || m.filterEditing || m.addingTask || m.runningTask { + if m.annotating || m.dueEditing || m.prioritySelecting || m.searching || m.descEditing || m.tagsEditing || m.recurEditing || m.filterEditing || m.addingTask { h-- } if h < 1 { -- cgit v1.2.3 From 90f2d2efbf374f6ea82a46d2d701a099dbae1c89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20B=C3=BCtow?= <1224732+snonux@users.noreply.github.com> Date: Sun, 22 Jun 2025 17:05:01 +0300 Subject: Center help screen --- internal/ui/table.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'internal/ui/table.go') diff --git a/internal/ui/table.go b/internal/ui/table.go index c3e1748..47ab784 100644 --- a/internal/ui/table.go +++ b/internal/ui/table.go @@ -849,7 +849,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { // View renders the table UI. func (m Model) View() string { if m.showHelp { - return lipgloss.JoinVertical(lipgloss.Left, + lines := []string{ m.tbl.HelpView(), "enter/i: edit or expand cell", "E: edit task", @@ -872,7 +872,11 @@ func (m Model) View() string { "esc: close help/search", "q: quit", "H: help", // show help toggle line - ) + } + for i, l := range lines { + lines[i] = centerLines(l, m.tbl.Width()) + } + return lipgloss.JoinVertical(lipgloss.Top, lines...) } view := lipgloss.JoinVertical(lipgloss.Left, m.topStatusLine(), @@ -1363,3 +1367,12 @@ func (m *Model) applyTheme() { m.tblStyles.Highlight = m.tblStyles.Highlight.Background(lipgloss.Color(m.theme.RowBG)).Foreground(lipgloss.Color(m.theme.RowFG)) m.tbl.SetStyles(m.tblStyles) } + +func centerLines(s string, width int) string { + lines := strings.Split(strings.TrimRight(s, "\n"), "\n") + style := lipgloss.NewStyle().Width(width).Align(lipgloss.Center) + for i, l := range lines { + lines[i] = style.Render(l) + } + return strings.Join(lines, "\n") +} -- cgit v1.2.3