diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-03 23:51:15 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-03 23:51:15 +0200 |
| commit | e785973bc3a0add31a7ff68a94b9ea5d43413b59 (patch) | |
| tree | 8ef9eb92a558d3f08e4057fc41bf0bdd7ff88f19 | |
| parent | ff4102a1881ed8a9ea322bc2d8146c8a7ece9efb (diff) | |
tui: standardize model receivers to pointers
| -rw-r--r-- | internal/tui/entries.go | 30 | ||||
| -rw-r--r-- | internal/tui/report.go | 16 | ||||
| -rw-r--r-- | internal/tui/tui.go | 20 | ||||
| -rw-r--r-- | internal/tui/tui_test.go | 20 |
4 files changed, 43 insertions, 43 deletions
diff --git a/internal/tui/entries.go b/internal/tui/entries.go index 2a10d21..180502d 100644 --- a/internal/tui/entries.go +++ b/internal/tui/entries.go @@ -90,10 +90,10 @@ func (m *EntriesModel) SetEntries(entries []worktime.Entry) { } // Update handles keyboard navigation and search/filter/edit interaction. -func (m EntriesModel) Update(msg tea.Msg) (EntriesModel, tea.Cmd) { +func (m *EntriesModel) Update(msg tea.Msg) (EntriesModel, tea.Cmd) { keyMsg, ok := msg.(tea.KeyMsg) if !ok { - return m, nil + return *m, nil } if m.confirmDelete { @@ -108,7 +108,7 @@ func (m EntriesModel) Update(msg tea.Msg) (EntriesModel, tea.Cmd) { case "n", "esc": m.confirmDelete = false } - return m, nil + return *m, nil } if m.editMode { @@ -133,7 +133,7 @@ func (m EntriesModel) Update(msg tea.Msg) (EntriesModel, tea.Cmd) { m.input += string(keyMsg.Runes) } } - return m, nil + return *m, nil } if m.searchMode || m.filterMode { @@ -161,7 +161,7 @@ func (m EntriesModel) Update(msg tea.Msg) (EntriesModel, tea.Cmd) { m.input += string(keyMsg.Runes) } } - return m, nil + return *m, nil } switch keyMsg.String() { @@ -195,7 +195,7 @@ func (m EntriesModel) Update(msg tea.Msg) (EntriesModel, tea.Cmd) { if m.pendingD { m.confirmDelete = true m.pendingD = false - return m, nil + return *m, nil } m.pendingD = true m.pendingG = false @@ -218,7 +218,7 @@ func (m EntriesModel) Update(msg tea.Msg) (EntriesModel, tea.Cmd) { m.ensureCursorVisible() m.pendingG = false m.pendingD = false - return m, nil + return *m, nil } m.pendingG = true m.pendingD = false @@ -243,11 +243,11 @@ func (m EntriesModel) Update(msg tea.Msg) (EntriesModel, tea.Cmd) { m.pendingD = false } - return m, nil + return *m, nil } // View renders the entries list. -func (m EntriesModel) View(styles Styles) string { +func (m *EntriesModel) View(styles Styles) string { title := fmt.Sprintf("Entries [%d/%d]", minInt(m.cursor+1, len(m.visible)), len(m.visible)) if m.filterQuery != "" { title += " filter:" + m.filterQuery @@ -482,7 +482,7 @@ func (m *EntriesModel) replaceEntry(oldEntry, newEntry worktime.Entry) { } } -func (m EntriesModel) persistReplacement(oldEntry, newEntry worktime.Entry) error { +func (m *EntriesModel) persistReplacement(oldEntry, newEntry worktime.Entry) error { if m.dbDir == "" { return nil } @@ -502,7 +502,7 @@ func (m EntriesModel) persistReplacement(oldEntry, newEntry worktime.Entry) erro return err } -func (m EntriesModel) persistDelete(target worktime.Entry) error { +func (m *EntriesModel) persistDelete(target worktime.Entry) error { if m.dbDir == "" { return nil } @@ -531,7 +531,7 @@ func (m *EntriesModel) setStatusError(message string) { m.statusError = true } -func (m EntriesModel) renderStatus(styles Styles) string { +func (m *EntriesModel) renderStatus(styles Styles) string { if strings.TrimSpace(m.statusMessage) == "" { return "" } @@ -566,7 +566,7 @@ func (m *EntriesModel) ensureCursorVisible() { } } -func (m EntriesModel) listRows() int { +func (m *EntriesModel) listRows() int { rows := m.height - 4 if rows < 1 { return 1 @@ -574,7 +574,7 @@ func (m EntriesModel) listRows() int { return rows } -func (m EntriesModel) halfPage() int { +func (m *EntriesModel) halfPage() int { page := m.listRows() / 2 if page < 1 { return 1 @@ -582,7 +582,7 @@ func (m EntriesModel) halfPage() int { return page } -func (m EntriesModel) pageSize() int { +func (m *EntriesModel) pageSize() int { page := m.listRows() if page < 1 { return 1 diff --git a/internal/tui/report.go b/internal/tui/report.go index ca680c3..a0ced04 100644 --- a/internal/tui/report.go +++ b/internal/tui/report.go @@ -59,10 +59,10 @@ func (m *ReportModel) SetWeeks(weeks []worktime.WeekReport) { } // Update handles keyboard interaction. -func (m ReportModel) Update(msg tea.Msg) (ReportModel, tea.Cmd) { +func (m *ReportModel) Update(msg tea.Msg) (ReportModel, tea.Cmd) { keyMsg, ok := msg.(tea.KeyMsg) if !ok { - return m, nil + return *m, nil } if m.pendingBracket != 0 { @@ -73,7 +73,7 @@ func (m ReportModel) Update(msg tea.Msg) (ReportModel, tea.Cmd) { m.prevWeek() } m.pendingBracket = 0 - return m, nil + return *m, nil } m.pendingBracket = 0 } @@ -94,7 +94,7 @@ func (m ReportModel) Update(msg tea.Msg) (ReportModel, tea.Cmd) { m.cursor = 0 m.ensureCursorVisible() m.pendingG = false - return m, nil + return *m, nil } m.pendingG = true case "]": @@ -110,11 +110,11 @@ func (m ReportModel) Update(msg tea.Msg) (ReportModel, tea.Cmd) { m.pendingG = false } - return m, nil + return *m, nil } // View renders the report screen. -func (m ReportModel) View(styles Styles) string { +func (m *ReportModel) View(styles Styles) string { if len(m.weeks) == 0 { return styles.Body.Render("Report\n\nNo report data.") } @@ -238,7 +238,7 @@ func (m *ReportModel) prevWeek() { m.offset = 0 } -func (m ReportModel) listRows() int { +func (m *ReportModel) listRows() int { rows := m.height - 7 if rows < 1 { return 1 @@ -246,7 +246,7 @@ func (m ReportModel) listRows() int { return rows } -func (m ReportModel) rowCount() int { +func (m *ReportModel) rowCount() int { if len(m.weeks) == 0 { return 0 } diff --git a/internal/tui/tui.go b/internal/tui/tui.go index b345e8b..3c2e6e9 100644 --- a/internal/tui/tui.go +++ b/internal/tui/tui.go @@ -41,14 +41,14 @@ type Model struct { } // NewModel creates a new root TUI model. -func NewModel() Model { +func NewModel() *Model { model, _ := NewModelWithConfig(config.Default()) return model } // NewModelWithConfig creates a data-backed root model from config. -func NewModelWithConfig(cfg config.Config) (Model, error) { - model := Model{ +func NewModelWithConfig(cfg config.Config) (*Model, error) { + model := &Model{ activeTab: tabEntries, styles: DefaultStyles(), entries: NewEntriesModel(nil), @@ -80,7 +80,7 @@ func NewModelWithConfig(cfg config.Config) (Model, error) { } // Init implements tea.Model. -func (m Model) Init() tea.Cmd { +func (m *Model) Init() tea.Cmd { if m.activeTab == tabTimer && m.timer.state.Running { return timerTick() } @@ -88,7 +88,7 @@ func (m Model) Init() tea.Cmd { } // Update implements tea.Model. -func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case tea.WindowSizeMsg: m.width = msg.Width @@ -146,7 +146,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } // View implements tea.Model. -func (m Model) View() string { +func (m *Model) View() string { header := m.renderTabs() body := m.renderBody() @@ -176,7 +176,7 @@ func (m *Model) prevTab() tea.Cmd { return m.switchTab(next) } -func (m Model) renderTabs() string { +func (m *Model) renderTabs() string { parts := make([]string, 0, len(tabLabels)) for idx, label := range tabLabels { if tab(idx) == m.activeTab { @@ -188,7 +188,7 @@ func (m Model) renderTabs() string { return m.styles.Header.Render(strings.Join(parts, " ")) } -func (m Model) renderBody() string { +func (m *Model) renderBody() string { switch m.activeTab { case tabEntries: if m.entriesErr != "" { @@ -228,7 +228,7 @@ func (m *Model) switchTab(next tab) tea.Cmd { return nil } -func (m Model) bodySize() (int, int) { +func (m *Model) bodySize() (int, int) { width := m.width - 4 height := m.height - 6 @@ -247,7 +247,7 @@ func (m Model) bodySize() (int, int) { return width, height } -func (m Model) updateActiveTab(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m *Model) updateActiveTab(msg tea.Msg) (tea.Model, tea.Cmd) { switch m.activeTab { case tabEntries: updated, cmd := m.entries.Update(msg) diff --git a/internal/tui/tui_test.go b/internal/tui/tui_test.go index 2822173..efeb005 100644 --- a/internal/tui/tui_test.go +++ b/internal/tui/tui_test.go @@ -14,21 +14,21 @@ func TestTabNavigation(t *testing.T) { model := newRootModelForTest(t) modelAny, _ := model.Update(tea.KeyMsg{Type: tea.KeyTab}) - model = modelAny.(Model) + model = modelAny.(*Model) if model.activeTab != tabReport { t.Fatalf("active tab after Tab = %v, want %v", model.activeTab, tabReport) } modelAny, _ = model.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'g'}}) - model = modelAny.(Model) + model = modelAny.(*Model) modelAny, _ = model.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'T'}}) - model = modelAny.(Model) + model = modelAny.(*Model) if model.activeTab != tabEntries { t.Fatalf("active tab after gT = %v, want %v", model.activeTab, tabEntries) } modelAny, _ = model.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'3'}}) - model = modelAny.(Model) + model = modelAny.(*Model) if model.activeTab != tabTimer { t.Fatalf("active tab after key 3 = %v, want %v", model.activeTab, tabTimer) } @@ -38,13 +38,13 @@ func TestHelpToggle(t *testing.T) { model := newRootModelForTest(t) modelAny, _ := model.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'?'}}) - model = modelAny.(Model) + model = modelAny.(*Model) if !model.showHelp { t.Fatal("showHelp = false, want true after ?") } modelAny, _ = model.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'?'}}) - model = modelAny.(Model) + model = modelAny.(*Model) if model.showHelp { t.Fatal("showHelp = true, want false after second ?") } @@ -54,7 +54,7 @@ func TestQuitKeys(t *testing.T) { model := newRootModelForTest(t) modelAny, cmd := model.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'q'}}) - model = modelAny.(Model) + model = modelAny.(*Model) if cmd == nil { t.Fatal("quit cmd is nil for q") } @@ -63,9 +63,9 @@ func TestQuitKeys(t *testing.T) { } modelAny, _ = model.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'Z'}}) - model = modelAny.(Model) + model = modelAny.(*Model) modelAny, cmd = model.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'Q'}}) - model = modelAny.(Model) + model = modelAny.(*Model) if cmd == nil { t.Fatal("quit cmd is nil for ZQ") } @@ -90,7 +90,7 @@ func TestEntriesTabUsesEntriesModelView(t *testing.T) { } } -func newRootModelForTest(t *testing.T) Model { +func newRootModelForTest(t *testing.T) *Model { t.Helper() tempDir := t.TempDir() |
