Skip to content

Commit

Permalink
feat: <enter> goes to state page
Browse files Browse the repository at this point in the history
  • Loading branch information
leg100 committed Aug 21, 2024
1 parent b06646b commit f7cd452
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 20 deletions.
2 changes: 1 addition & 1 deletion hacks/watch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 0 additions & 5 deletions internal/tui/keys/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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("<space>", "select"),
Expand Down
14 changes: 14 additions & 0 deletions internal/tui/logs/keys.go
Original file line number Diff line number Diff line change
@@ -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"),
),
}
7 changes: 3 additions & 4 deletions internal/tui/logs/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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))
}
Expand All @@ -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}
}
5 changes: 5 additions & 0 deletions internal/tui/module/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
type keyMap struct {
ReloadModules key.Binding
ReloadWorkspaces key.Binding
Enter key.Binding
}

var localKeys = keyMap{
Expand All @@ -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"),
),
}
16 changes: 11 additions & 5 deletions internal/tui/module/list.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package module

import (
"errors"
"fmt"
"strings"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -225,5 +230,6 @@ func (m list) HelpBindings() (bindings []key.Binding) {
keys.Common.Edit,
localKeys.ReloadModules,
localKeys.ReloadWorkspaces,
keys.Common.State,
}
}
3 changes: 1 addition & 2 deletions internal/tui/task/group_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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))
}
Expand Down
16 changes: 16 additions & 0 deletions internal/tui/task/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,27 @@ import "github.com/charmbracelet/bubbles/key"

type keyMap struct {
ToggleInfo key.Binding
Enter key.Binding
}

var localKeys = keyMap{
ToggleInfo: key.NewBinding(
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"),
),
}
2 changes: 1 addition & 1 deletion internal/tui/task/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
10 changes: 10 additions & 0 deletions internal/tui/workspace/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,26 @@ import (

type keyMap struct {
SetCurrent key.Binding
Enter key.Binding
}

var localKeys = keyMap{
SetCurrent: key.NewBinding(
key.WithKeys("C"),
key.WithHelp("C", "set current"),
),
Enter: key.NewBinding(
key.WithKeys("enter"),
key.WithHelp("enter", "state"),
),
}

type resourcesKeyMap struct {
Taint key.Binding
Untaint key.Binding
Move key.Binding
Reload key.Binding
Enter key.Binding
}

var resourcesKeys = resourcesKeyMap{
Expand All @@ -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"),
),
}
3 changes: 2 additions & 1 deletion internal/tui/workspace/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -192,6 +192,7 @@ func (m list) HelpBindings() []key.Binding {
keys.Common.Delete,
keys.Common.Cost,
localKeys.SetCurrent,
keys.Common.State,
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/tui/workspace/resource_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down

0 comments on commit f7cd452

Please sign in to comment.