diff --git a/hacks/watch.sh b/hacks/watch.sh index 9a42b13..c158430 100755 --- a/hacks/watch.sh +++ b/hacks/watch.sh @@ -2,5 +2,5 @@ # in foreground, continously run app while true; do - _build/pug -w ./demo -d -l debug + _build/pug -w ./demo/dont_cost_money -d -l debug done diff --git a/internal/tui/keys/global.go b/internal/tui/keys/global.go index fbd2598..785ec18 100644 --- a/internal/tui/keys/global.go +++ b/internal/tui/keys/global.go @@ -11,7 +11,6 @@ type global struct { TaskGroups key.Binding Logs key.Binding Back key.Binding - Enter key.Binding Select key.Binding SelectAll key.Binding SelectClear key.Binding @@ -47,10 +46,6 @@ var Global = global{ key.WithKeys("esc"), key.WithHelp("esc", "back"), ), - Enter: key.NewBinding( - key.WithKeys("enter"), - key.WithHelp("enter", "view"), - ), Select: key.NewBinding( key.WithKeys(" "), key.WithHelp("", "select"), diff --git a/internal/tui/logs/keys.go b/internal/tui/logs/keys.go new file mode 100644 index 0000000..f6af988 --- /dev/null +++ b/internal/tui/logs/keys.go @@ -0,0 +1,14 @@ +package logs + +import "github.com/charmbracelet/bubbles/key" + +type keyMap struct { + Enter key.Binding +} + +var localKeys = keyMap{ + Enter: key.NewBinding( + key.WithKeys("enter"), + key.WithHelp("enter", "view message"), + ), +} diff --git a/internal/tui/logs/list.go b/internal/tui/logs/list.go index dc0808e..0d463d5 100644 --- a/internal/tui/logs/list.go +++ b/internal/tui/logs/list.go @@ -8,7 +8,6 @@ import ( "github.com/leg100/pug/internal/logging" "github.com/leg100/pug/internal/resource" "github.com/leg100/pug/internal/tui" - "github.com/leg100/pug/internal/tui/keys" "github.com/leg100/pug/internal/tui/table" ) @@ -87,7 +86,7 @@ func (m list) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyMsg: switch { - case key.Matches(msg, keys.Global.Enter): + case key.Matches(msg, localKeys.Enter): if row, ok := m.table.CurrentRow(); ok { return m, tui.NavigateTo(tui.LogKind, tui.WithParent(row.ID)) } @@ -109,6 +108,6 @@ func (m list) View() string { return m.table.View() } -func (m list) HelpBindings() (bindings []key.Binding) { - return nil +func (m list) HelpBindings() []key.Binding { + return []key.Binding{localKeys.Enter} } diff --git a/internal/tui/module/keys.go b/internal/tui/module/keys.go index c0a2796..53f29de 100644 --- a/internal/tui/module/keys.go +++ b/internal/tui/module/keys.go @@ -7,6 +7,7 @@ import ( type keyMap struct { ReloadModules key.Binding ReloadWorkspaces key.Binding + Enter key.Binding } var localKeys = keyMap{ @@ -18,4 +19,8 @@ var localKeys = keyMap{ key.WithKeys("ctrl+w"), key.WithHelp("ctrl+w", "reload workspaces"), ), + Enter: key.NewBinding( + key.WithKeys("enter"), + key.WithHelp("enter", "state"), + ), } diff --git a/internal/tui/module/list.go b/internal/tui/module/list.go index f368ed1..67892c6 100644 --- a/internal/tui/module/list.go +++ b/internal/tui/module/list.go @@ -1,6 +1,7 @@ package module import ( + "errors" "fmt" "strings" @@ -149,12 +150,16 @@ func (m list) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case key.Matches(msg, localKeys.ReloadWorkspaces): cmd := m.helpers.CreateTasks(m.Workspaces.Reload, m.table.SelectedOrCurrentIDs()...) return m, cmd - case key.Matches(msg, keys.Common.State): - if row, ok := m.table.CurrentRow(); ok { - if ws := m.helpers.ModuleCurrentWorkspace(row.Value); ws != nil { - return m, tui.NavigateTo(tui.ResourceListKind, tui.WithParent(ws.ID)) - } + case key.Matches(msg, keys.Common.State, localKeys.Enter): + row, ok := m.table.CurrentRow() + if !ok { + return m, nil + } + ws := m.helpers.ModuleCurrentWorkspace(row.Value) + if ws == nil { + return m, tui.ReportError(errors.New("module does not have a current workspace")) } + return m, tui.NavigateTo(tui.ResourceListKind, tui.WithParent(ws.ID)) case key.Matches(msg, keys.Common.PlanDestroy): createPlanOpts.Destroy = true fallthrough @@ -225,5 +230,6 @@ func (m list) HelpBindings() (bindings []key.Binding) { keys.Common.Edit, localKeys.ReloadModules, localKeys.ReloadWorkspaces, + keys.Common.State, } } diff --git a/internal/tui/task/group_list.go b/internal/tui/task/group_list.go index 5dff3ed..c40952b 100644 --- a/internal/tui/task/group_list.go +++ b/internal/tui/task/group_list.go @@ -8,7 +8,6 @@ import ( "github.com/leg100/pug/internal/resource" "github.com/leg100/pug/internal/task" "github.com/leg100/pug/internal/tui" - "github.com/leg100/pug/internal/tui/keys" "github.com/leg100/pug/internal/tui/table" ) @@ -79,7 +78,7 @@ func (m groupList) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyMsg: switch { - case key.Matches(msg, keys.Global.Enter): + case key.Matches(msg, groupListKeys.Enter): if row, ok := m.table.CurrentRow(); ok { return m, tui.NavigateTo(tui.TaskGroupKind, tui.WithParent(row.ID)) } diff --git a/internal/tui/task/keys.go b/internal/tui/task/keys.go index e5380e0..49b39e5 100644 --- a/internal/tui/task/keys.go +++ b/internal/tui/task/keys.go @@ -4,6 +4,7 @@ import "github.com/charmbracelet/bubbles/key" type keyMap struct { ToggleInfo key.Binding + Enter key.Binding } var localKeys = keyMap{ @@ -11,4 +12,19 @@ var localKeys = keyMap{ key.WithKeys("I"), key.WithHelp("I", "toggle info"), ), + Enter: key.NewBinding( + key.WithKeys("enter"), + key.WithHelp("enter", "view task"), + ), +} + +type groupListKeyMap struct { + Enter key.Binding +} + +var groupListKeys = groupListKeyMap{ + Enter: key.NewBinding( + key.WithKeys("enter"), + key.WithHelp("enter", "view group"), + ), } diff --git a/internal/tui/task/list.go b/internal/tui/task/list.go index fdb40ab..4f6a63d 100644 --- a/internal/tui/task/list.go +++ b/internal/tui/task/list.go @@ -134,7 +134,7 @@ func (m List) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case key.Matches(msg, keys.Common.Cancel): taskIDs := m.Table.SelectedOrCurrentIDs() return m, cancel(m.tasks, taskIDs...) - case key.Matches(msg, keys.Global.Enter): + case key.Matches(msg, localKeys.Enter): if row, ok := m.Table.CurrentRow(); ok { return m, tui.NavigateTo(tui.TaskKind, tui.WithParent(row.ID)) } diff --git a/internal/tui/workspace/keys.go b/internal/tui/workspace/keys.go index 5e26e50..a3cd48b 100644 --- a/internal/tui/workspace/keys.go +++ b/internal/tui/workspace/keys.go @@ -6,6 +6,7 @@ import ( type keyMap struct { SetCurrent key.Binding + Enter key.Binding } var localKeys = keyMap{ @@ -13,6 +14,10 @@ var localKeys = keyMap{ key.WithKeys("C"), key.WithHelp("C", "set current"), ), + Enter: key.NewBinding( + key.WithKeys("enter"), + key.WithHelp("enter", "state"), + ), } type resourcesKeyMap struct { @@ -20,6 +25,7 @@ type resourcesKeyMap struct { Untaint key.Binding Move key.Binding Reload key.Binding + Enter key.Binding } var resourcesKeys = resourcesKeyMap{ @@ -39,4 +45,8 @@ var resourcesKeys = resourcesKeyMap{ key.WithKeys("ctrl+r"), key.WithHelp("ctrl+r", "reload"), ), + Enter: key.NewBinding( + key.WithKeys("enter"), + key.WithHelp("enter", "view resource"), + ), } diff --git a/internal/tui/workspace/list.go b/internal/tui/workspace/list.go index a3dc875..2814d84 100644 --- a/internal/tui/workspace/list.go +++ b/internal/tui/workspace/list.go @@ -151,7 +151,7 @@ func (m list) Update(msg tea.Msg) (tea.Model, tea.Cmd) { fmt.Sprintf(applyPrompt, len(workspaceIDs)), m.helpers.CreateTasks(fn, workspaceIDs...), ) - case key.Matches(msg, keys.Common.State): + case key.Matches(msg, keys.Common.State, localKeys.Enter): if row, ok := m.table.CurrentRow(); ok { return m, tui.NavigateTo(tui.ResourceListKind, tui.WithParent(row.ID)) } @@ -192,6 +192,7 @@ func (m list) HelpBindings() []key.Binding { keys.Common.Delete, keys.Common.Cost, localKeys.SetCurrent, + keys.Common.State, } } diff --git a/internal/tui/workspace/resource_list.go b/internal/tui/workspace/resource_list.go index 91e39f6..c8c8a61 100644 --- a/internal/tui/workspace/resource_list.go +++ b/internal/tui/workspace/resource_list.go @@ -126,7 +126,7 @@ func (m resourceList) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, tui.ReportInfo("reloading finished") case tea.KeyMsg: switch { - case key.Matches(msg, keys.Global.Enter): + case key.Matches(msg, localKeys.Enter): if row, ok := m.Table.CurrentRow(); ok { return m, tui.NavigateTo(tui.ResourceKind, tui.WithParent(row.ID)) }