refactor(tui): decompose god files into single-concern modules #53

Merged
lerko merged 1 commits from refactor/tui-god-files into main 2026-06-03 02:11:49 +00:00
Owner

Summary

  • tui.go (1032→164 lines, -84%): extracted Update handlers, View composition, data management, and utility functions into dedicated files
  • tab_sites.go (993→482 lines, -51%): extracted formatting, sparklines, and detail panel into their own modules
  • Added 17 unit tests for pure functions that were previously untestable (format, sparkline, sort/filter)

What moved where

New file Concern Lines
update.go Update method + 15 named key/mouse/form handlers 539
view_dashboard.go View dispatch, dashboard layout, tab bar, footer 279
view_detail.go Site detail panel 207
format.go Pure formatting (fmtLatency, fmtUptime, fmtSSL, etc.) 171
sparkline.go Sparkline rendering (latency, heartbeat, group) 174
data.go refreshData, sortSitesForDisplay, filterSites, collapsed persistence 124

No behavioral changes — strict move-and-extract refactor. All existing tests pass.

Test plan

  • go build ./... — clean
  • go vet ./internal/tui/ — clean
  • go test ./... — all pass (17 new TUI tests + all existing)
  • Manual: launch TUI, verify all tabs render, forms work, keybinds respond
## Summary - **tui.go** (1032→164 lines, -84%): extracted Update handlers, View composition, data management, and utility functions into dedicated files - **tab_sites.go** (993→482 lines, -51%): extracted formatting, sparklines, and detail panel into their own modules - Added 17 unit tests for pure functions that were previously untestable (format, sparkline, sort/filter) ## What moved where | New file | Concern | Lines | |---|---|---| | `update.go` | Update method + 15 named key/mouse/form handlers | 539 | | `view_dashboard.go` | View dispatch, dashboard layout, tab bar, footer | 279 | | `view_detail.go` | Site detail panel | 207 | | `format.go` | Pure formatting (fmtLatency, fmtUptime, fmtSSL, etc.) | 171 | | `sparkline.go` | Sparkline rendering (latency, heartbeat, group) | 174 | | `data.go` | refreshData, sortSitesForDisplay, filterSites, collapsed persistence | 124 | No behavioral changes — strict move-and-extract refactor. All existing tests pass. ## Test plan - [x] `go build ./...` — clean - [x] `go vet ./internal/tui/` — clean - [x] `go test ./...` — all pass (17 new TUI tests + all existing) - [x] Manual: launch TUI, verify all tabs render, forms work, keybinds respond
lerko added 1 commit 2026-06-03 01:06:44 +00:00
refactor(tui): decompose god files into single-concern modules
CI / test (pull_request) Successful in 2m34s
CI / lint (pull_request) Successful in 56s
CI / vulncheck (pull_request) Successful in 51s
CI / test (push) Successful in 2m32s
CI / lint (push) Successful in 56s
CI / vulncheck (push) Successful in 51s
5d362fdbe6
tui.go (1032→164) and tab_sites.go (993→482) violated "small functions"
and "testable in isolation" standards. Extracted 6 new files by concern:

- format.go: pure formatting functions (fmtLatency, fmtUptime, etc.)
- sparkline.go: sparkline rendering (latency, heartbeat, group)
- update.go: Update method decomposed into 15 named handlers
- view_dashboard.go: View, dashboard composition, tab bar, footer
- view_detail.go: site detail panel
- data.go: data refresh with extracted sortSitesForDisplay/filterSites

Added 17 unit tests for the newly-testable pure functions covering
format, sparkline, sort ordering, and filter logic. No behavioral
changes — strict move-and-extract refactor.
lerko merged commit 5d362fdbe6 into main 2026-06-03 02:11:49 +00:00
lerko deleted branch refactor/tui-god-files 2026-06-03 02:11:49 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: lerkolabs/uptop#53