diff options
| author | Paul Bütow <1224732+snonux@users.noreply.github.com> | 2025-06-20 00:09:33 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-20 00:09:33 +0300 |
| commit | 77620dcd609aa53a81effd23174d56e622f16cc8 (patch) | |
| tree | 8c1c605913013d16fafe865729e7ac236eb5b594 | |
| parent | 15dcd6f5baad135b1472b79886bce9a77189dcf3 (diff) | |
| parent | 0dd71db839d29b638e3072259bc9ab44c6864a2d (diff) | |
Merge pull request #8 from snonux/codex/update-ui,-add-hotkeys,-and-help-screen
Improve UI with time-based due dates and help
| -rw-r--r-- | cmd/tasksamurai/main.go | 19 | ||||
| -rw-r--r-- | internal/ui/table.go | 34 |
2 files changed, 46 insertions, 7 deletions
diff --git a/cmd/tasksamurai/main.go b/cmd/tasksamurai/main.go index 424d0d8..658cb05 100644 --- a/cmd/tasksamurai/main.go +++ b/cmd/tasksamurai/main.go @@ -7,6 +7,8 @@ import ( "strings" "time" + "github.com/charmbracelet/lipgloss" + "tasksamurai/internal/task" "tasksamurai/internal/ui" @@ -66,18 +68,25 @@ func taskToRow(t task.Task) table.Row { t.Priority, tags, t.Recur, - formatDate(t.Due), + formatDue(t.Due), urg, strings.Join(anns, "; "), } } -func formatDate(s string) string { +func formatDue(s string) string { if s == "" { return "" } - if ts, err := time.Parse("20060102T150405Z", s); err == nil { - return ts.Format("2006-01-02") + ts, err := time.Parse("20060102T150405Z", s) + if err != nil { + return s + } + + days := int(time.Until(ts).Hours() / 24) + val := fmt.Sprintf("%dd", days) + if days < 0 { + val = lipgloss.NewStyle().Background(lipgloss.Color("1")).Render(val) } - return s + return val } diff --git a/internal/ui/table.go b/internal/ui/table.go index 682a680..af85acb 100644 --- a/internal/ui/table.go +++ b/internal/ui/table.go @@ -7,7 +7,10 @@ import ( ) // Model wraps a Bubble Tea table.Model to display tasks. -type Model struct{ tbl table.Model } +type Model struct { + tbl table.Model + showHelp bool +} // New creates a new UI model with the provided rows. func New(rows []table.Row) Model { @@ -45,11 +48,38 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case tea.WindowSizeMsg: m.tbl.SetWidth(msg.Width) m.tbl.SetHeight(msg.Height - 2) + return m, nil + case tea.KeyMsg: + switch msg.String() { + case "?": + m.showHelp = true + return m, nil + case "q": + if m.showHelp { + m.showHelp = false + return m, nil + } + return m, tea.Quit + } + } + + if m.showHelp { + return m, nil } + var cmd tea.Cmd m.tbl, cmd = m.tbl.Update(msg) return m, cmd } // View renders the table UI. -func (m Model) View() string { return m.tbl.View() } +func (m Model) View() string { + if m.showHelp { + return lipgloss.JoinVertical(lipgloss.Left, + m.tbl.HelpView(), + "q: quit", + "?: help", // show help toggle line + ) + } + return m.tbl.View() +} |
