diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-13 20:04:48 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-13 20:04:48 +0300 |
| commit | 251894cf3375812564ecf28392179b395cdda9c7 (patch) | |
| tree | 83c3609ab591702e29a375923670e7622a33b5c7 /internal/tui/export | |
| parent | 78ea9e22e596255c5e23ce445d80641870674ca9 (diff) | |
refactor: break down functions exceeding 50 lines into smaller helpers
Split 22 production files across the codebase — event loop, TUI models,
probe manager, dashboard, export, flag parsing, code generation, and
ioworkload scenarios — so that no function body exceeds 50 lines. Each
extracted helper carries its own comment explaining its role.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/tui/export')
| -rw-r--r-- | internal/tui/export/model.go | 69 |
1 files changed, 37 insertions, 32 deletions
diff --git a/internal/tui/export/model.go b/internal/tui/export/model.go index 7cef65a..085645d 100644 --- a/internal/tui/export/model.go +++ b/internal/tui/export/model.go @@ -76,38 +76,7 @@ func (m Model) Close() Model { func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyPressMsg: - if !m.visible { - return m, nil - } - if m.exporting { - if msg.String() == "esc" { - return m.Close(), nil - } - return m, nil - } - - switch msg.String() { - case "esc": - return m.Close(), nil - case "up", "k": - if m.selected > 0 { - m.selected-- - } - return m, nil - case "down", "j": - if m.selected < len(optionValues)-1 { - m.selected++ - } - return m, nil - case "enter": - option := optionValues[m.selected] - if option == OptionCancel { - return m.Close(), nil - } - m.exporting = true - m.status = fmt.Sprintf("Exporting %s...", optionLabels[m.selected]) - return m, func() tea.Msg { return RequestMsg{Option: option} } - } + return m.handleKeyMsg(msg) case CompletedMsg: m.exporting = false if msg.Path == "" { @@ -123,7 +92,43 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { m.status = "Export failed: " + msg.Err.Error() return m, nil } + return m, nil +} +// handleKeyMsg processes key presses when the modal is visible. It delegates +// to the export-in-progress handler or the navigation handler as appropriate. +func (m Model) handleKeyMsg(msg tea.KeyPressMsg) (Model, tea.Cmd) { + if !m.visible { + return m, nil + } + if m.exporting { + if msg.String() == "esc" { + return m.Close(), nil + } + return m, nil + } + switch msg.String() { + case "esc": + return m.Close(), nil + case "up", "k": + if m.selected > 0 { + m.selected-- + } + return m, nil + case "down", "j": + if m.selected < len(optionValues)-1 { + m.selected++ + } + return m, nil + case "enter": + option := optionValues[m.selected] + if option == OptionCancel { + return m.Close(), nil + } + m.exporting = true + m.status = fmt.Sprintf("Exporting %s...", optionLabels[m.selected]) + return m, func() tea.Msg { return RequestMsg{Option: option} } + } return m, nil } |
