diff options
| author | Adam Mathes <adam@adammathes.com> | 2026-02-12 20:57:12 -0800 |
|---|---|---|
| committer | Adam Mathes <adam@adammathes.com> | 2026-02-12 20:57:12 -0800 |
| commit | cfd583e9166330f053fa7cc28258b4467c48459c (patch) | |
| tree | bdea6e91c25e04b6e483a58040d386876593a457 /tui/tui.go | |
| parent | fa037e748bb2ba65f75ba104e18d460a8fbcd49b (diff) | |
| download | neko-cfd583e9166330f053fa7cc28258b4467c48459c.tar.gz neko-cfd583e9166330f053fa7cc28258b4467c48459c.tar.bz2 neko-cfd583e9166330f053fa7cc28258b4467c48459c.zip | |
Fix nil-pointer panics in TUI and add unit tests
- Initialized list models in NewModel to prevent panic on WindowSizeMsg
- Added nil check for selectedFeed in itemsMsg handler
- Created tui/tui_test.go with unit tests for state transitions and resizing
- Verified all tests pass
Diffstat (limited to 'tui/tui.go')
| -rw-r--r-- | tui/tui.go | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -54,9 +54,13 @@ type Model struct { } func NewModel() Model { - return Model{ + m := Model{ state: viewFeeds, } + // Initialize lists with empty items to avoid nil dereference in SetSize + m.feedList = list.New([]list.Item{}, list.NewDefaultDelegate(), 0, 0) + m.itemList = list.New([]list.Item{}, list.NewDefaultDelegate(), 0, 0) + return m } func (m Model) Init() tea.Cmd { @@ -113,7 +117,11 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { items[i] = itemString(it.Title) } m.itemList = list.New(items, list.NewDefaultDelegate(), m.width, m.height-4) - m.itemList.Title = m.selectedFeed.Title + if m.selectedFeed != nil { + m.itemList.Title = m.selectedFeed.Title + } else { + m.itemList.Title = "Items" + } m.state = viewItems case errMsg: |
