From 1e6751d6c0811e2740d648ef3a4d97811798481e Mon Sep 17 00:00:00 2001 From: Egutierrez Date: Sat, 28 Mar 2026 04:52:21 +0100 Subject: [PATCH] refactor: navegacion consistente con HandleBack en todas las vistas Cada vista expone HandleBack() bool que retrocede un nivel interno (logs -> lista) o indica que esta en estado base. El model principal intercepta q/0/esc y delega a HandleBack: si retorna true, sale de la TUI; si false, la vista retrocedio internamente. Elimina manejo duplicado de esc/q/0 en sub-estados. --- fn_operations/docker_tui/app/model.go | 29 ++++++++++++++++++++ fn_operations/docker_tui/views/compose.go | 14 ++++++++-- fn_operations/docker_tui/views/containers.go | 14 ++++++++-- fn_operations/docker_tui/views/images.go | 5 ++++ fn_operations/docker_tui/views/networks.go | 5 ++++ fn_operations/docker_tui/views/volumes.go | 5 ++++ 6 files changed, 66 insertions(+), 6 deletions(-) diff --git a/fn_operations/docker_tui/app/model.go b/fn_operations/docker_tui/app/model.go index c0d83f08..eeb6c71e 100644 --- a/fn_operations/docker_tui/app/model.go +++ b/fn_operations/docker_tui/app/model.go @@ -53,6 +53,12 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg.String() { case views.KeyQuit: return m, tea.Quit + case "q", "0", "esc": + updated, atBase := m.handleBack() + if atBase { + return updated, tea.Quit + } + return updated, nil case views.KeyTab: m.activeTab = (m.activeTab + 1) % len(tabNames) return m, m.initActiveView() @@ -129,6 +135,29 @@ func (m Model) renderTabs() string { return m.Styles.Header.Render("Docker TUI") + " " + row } +// handleBack asks the active view to go back one level. +// Returns the updated model and true if the view was already at base level (app should quit). +func (m Model) handleBack() (Model, bool) { + switch View(m.activeTab) { + case ViewContainers: + atBase := m.containers.HandleBack() + return m, atBase + case ViewImages: + atBase := m.images.HandleBack() + return m, atBase + case ViewVolumes: + atBase := m.volumes.HandleBack() + return m, atBase + case ViewNetworks: + atBase := m.networks.HandleBack() + return m, atBase + case ViewCompose: + atBase := m.compose.HandleBack() + return m, atBase + } + return m, true +} + func (m Model) initActiveView() tea.Cmd { switch View(m.activeTab) { case ViewContainers: diff --git a/fn_operations/docker_tui/views/compose.go b/fn_operations/docker_tui/views/compose.go index 18d1f588..ca35838e 100644 --- a/fn_operations/docker_tui/views/compose.go +++ b/fn_operations/docker_tui/views/compose.go @@ -134,9 +134,6 @@ func (m ComposeModel) Update(msg tea.Msg) (ComposeModel, tea.Cmd) { if m.scrollOff > 0 { m.scrollOff-- } - case "esc", "q", "0": - m.state = composeList - return m, nil } return m, nil } @@ -156,6 +153,17 @@ func (m ComposeModel) Update(msg tea.Msg) (ComposeModel, tea.Cmd) { return m, cmd } +// HandleBack retrocede un nivel. Retorna true si ya estaba en estado base. +func (m *ComposeModel) HandleBack() bool { + switch m.state { + case composeLogs: + m.state = composeList + return false + default: + return true + } +} + func (m ComposeModel) View() string { switch m.state { case composeLoading, composeAction: diff --git a/fn_operations/docker_tui/views/containers.go b/fn_operations/docker_tui/views/containers.go index 1dcf803c..40aa2d48 100644 --- a/fn_operations/docker_tui/views/containers.go +++ b/fn_operations/docker_tui/views/containers.go @@ -132,9 +132,6 @@ func (m ContainersModel) Update(msg tea.Msg) (ContainersModel, tea.Cmd) { if m.scrollOff > 0 { m.scrollOff-- } - case "esc", "q", "0": - m.state = containersList - return m, nil } return m, nil } @@ -155,6 +152,17 @@ func (m ContainersModel) Update(msg tea.Msg) (ContainersModel, tea.Cmd) { return m, cmd } +// HandleBack retrocede un nivel. Retorna true si ya estaba en estado base (el caller debe salir). +func (m *ContainersModel) HandleBack() bool { + switch m.state { + case containersLogs: + m.state = containersList + return false + default: + return true + } +} + func (m ContainersModel) View() string { switch m.state { case containersLoading: diff --git a/fn_operations/docker_tui/views/images.go b/fn_operations/docker_tui/views/images.go index ec989592..478a756b 100644 --- a/fn_operations/docker_tui/views/images.go +++ b/fn_operations/docker_tui/views/images.go @@ -108,6 +108,11 @@ func (m ImagesModel) Update(msg tea.Msg) (ImagesModel, tea.Cmd) { return m, cmd } +// HandleBack retrocede un nivel. Retorna true si ya estaba en estado base. +func (m *ImagesModel) HandleBack() bool { + return true +} + func (m ImagesModel) View() string { switch m.state { case imagesLoading, imagesAction: diff --git a/fn_operations/docker_tui/views/networks.go b/fn_operations/docker_tui/views/networks.go index 5c3aefac..076603b7 100644 --- a/fn_operations/docker_tui/views/networks.go +++ b/fn_operations/docker_tui/views/networks.go @@ -104,6 +104,11 @@ func (m NetworksModel) Update(msg tea.Msg) (NetworksModel, tea.Cmd) { return m, cmd } +// HandleBack retrocede un nivel. Retorna true si ya estaba en estado base. +func (m *NetworksModel) HandleBack() bool { + return true +} + func (m NetworksModel) View() string { switch m.state { case networksLoading, networksAction: diff --git a/fn_operations/docker_tui/views/volumes.go b/fn_operations/docker_tui/views/volumes.go index b55d4ec7..67999d8b 100644 --- a/fn_operations/docker_tui/views/volumes.go +++ b/fn_operations/docker_tui/views/volumes.go @@ -104,6 +104,11 @@ func (m VolumesModel) Update(msg tea.Msg) (VolumesModel, tea.Cmd) { return m, cmd } +// HandleBack retrocede un nivel. Retorna true si ya estaba en estado base. +func (m *VolumesModel) HandleBack() bool { + return true +} + func (m VolumesModel) View() string { switch m.state { case volumesLoading, volumesAction: