Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .ai/skills/new-command.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,13 @@ flow := &wizard.Flow{
Name: "s3-move",
Layout: []wizard.ViewDef{
{ID: "progress", View: wizard.NewProgressView(wizard.WithProgressPercent())},
{ID: "hints", View: wizard.NewHintBarView(wizard.WithHintStyle(bubbletea.HintStyle()))},
},
Steps: []wizard.Step{ /* ... */ },
}
```

Do not register a `HintBarView`: the wizard composite already renders its own hint bar, and a second one shows contradictory hints.

Per-step rules:
- Each `Step` binds to a variable via `Setter`/`Value`/`IsSet`/`Resetter`. `IsSet()==true` (e.g. a `--flag` was passed) makes the engine **skip** the step and propagate `Value()` into the collected map.
- `SelectPrompt` with a `Loader` for dynamic lists. A Loader may read earlier steps from `store.Collected()["<name>"]`; declare `DependsOn: []string{"<name>"}` so it re-runs when that input changes (e.g. mv's source-object list depends on the chosen source bucket).
Expand Down
2 changes: 0 additions & 2 deletions internal/verda-cli/cmd/auth/wizard.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"errors"
"strings"

"github.com/verda-cloud/verda-cli/pkg/tui/bubbletea"
"github.com/verda-cloud/verda-cli/pkg/tui/wizard"
)

Expand All @@ -35,7 +34,6 @@ func buildLoginFlow(opts *loginOptions) *wizard.Flow {
Name: "auth-login",
Layout: []wizard.ViewDef{
{ID: "progress", View: wizard.NewProgressView(wizard.WithProgressPercent())},
{ID: "hints", View: wizard.NewHintBarView(wizard.WithHintStyle(bubbletea.HintStyle()))},
},
Steps: []wizard.Step{
loginStepProfile(opts),
Expand Down
9 changes: 9 additions & 0 deletions internal/verda-cli/cmd/network/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,12 @@ func TestNameIsTrimmedAndCountedInCharacters(t *testing.T) {
t.Errorf("name must be trimmed: %s", body)
}
}

func TestWizardLayoutHasNoExtraHintBar(t *testing.T) {
t.Parallel()
for _, def := range wizardLayout() {
if _, ok := def.View.(*wizard.HintBarView); ok {
t.Fatalf("view %q duplicates the wizard composite's hint bar", def.ID)
}
}
}
2 changes: 0 additions & 2 deletions internal/verda-cli/cmd/network/wizard.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

"github.com/verda-cloud/verdacloud-sdk-go/pkg/verda"

"github.com/verda-cloud/verda-cli/pkg/tui/bubbletea"
"github.com/verda-cloud/verda-cli/pkg/tui/wizard"
)

Expand All @@ -43,7 +42,6 @@ func validateName(s string) error {
func wizardLayout() []wizard.ViewDef {
return []wizard.ViewDef{
{ID: "progress", View: wizard.NewProgressView(wizard.WithProgressPercent())},
{ID: "hints", View: wizard.NewHintBarView(wizard.WithHintStyle(bubbletea.HintStyle()))},
}
}

Expand Down
2 changes: 0 additions & 2 deletions internal/verda-cli/cmd/objectstorage/move_wizard.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/spf13/cobra"
"github.com/verda-cloud/verda-cli/pkg/tui"
"github.com/verda-cloud/verda-cli/pkg/tui/bubbletea"
"github.com/verda-cloud/verda-cli/pkg/tui/wizard"

cmdutil "github.com/verda-cloud/verda-cli/internal/verda-cli/cmd/util"
Expand Down Expand Up @@ -99,7 +98,6 @@ func buildMoveFlow(f cmdutil.Factory, client API, st *moveWizardState) *wizard.F
Name: "s3-move",
Layout: []wizard.ViewDef{
{ID: "progress", View: wizard.NewProgressView(wizard.WithProgressPercent())},
{ID: "hints", View: wizard.NewHintBarView(wizard.WithHintStyle(bubbletea.HintStyle()))},
},
Steps: []wizard.Step{
moveStepSourceBucket(f, client, st),
Expand Down
2 changes: 0 additions & 2 deletions internal/verda-cli/cmd/objectstorage/wizard.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"strings"

"github.com/verda-cloud/verda-cli/pkg/tui"
"github.com/verda-cloud/verda-cli/pkg/tui/bubbletea"
"github.com/verda-cloud/verda-cli/pkg/tui/wizard"

"github.com/verda-cloud/verda-cli/internal/verda-cli/options"
Expand All @@ -43,7 +42,6 @@ func buildConfigureFlow(opts *configureOptions) *wizard.Flow {
Name: "s3-configure",
Layout: []wizard.ViewDef{
{ID: "progress", View: wizard.NewProgressView(wizard.WithProgressPercent())},
{ID: "hints", View: wizard.NewHintBarView(wizard.WithHintStyle(bubbletea.HintStyle()))},
},
Steps: []wizard.Step{
configureStepProfile(opts),
Expand Down
2 changes: 0 additions & 2 deletions internal/verda-cli/cmd/registry/wizard.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"strings"

"github.com/verda-cloud/verda-cli/pkg/tui"
"github.com/verda-cloud/verda-cli/pkg/tui/bubbletea"
"github.com/verda-cloud/verda-cli/pkg/tui/wizard"

"github.com/verda-cloud/verda-cli/internal/verda-cli/options"
Expand Down Expand Up @@ -63,7 +62,6 @@ func buildConfigureFlow(opts *configureOptions) *wizard.Flow {
Name: "registry-configure",
Layout: []wizard.ViewDef{
{ID: "progress", View: wizard.NewProgressView(wizard.WithProgressPercent())},
{ID: "hints", View: wizard.NewHintBarView(wizard.WithHintStyle(bubbletea.HintStyle()))},
},
Steps: []wizard.Step{
configureStepProfile(opts),
Expand Down
2 changes: 1 addition & 1 deletion internal/verda-cli/cmd/settings/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
## Relationships
- `cmdutil.Factory` / `cmdutil.IOStreams` -- standard dependency injection
- `options` package -- `SaveSetting()` for persisting to config YAML
- `pkg/tui/wizard` -- wizard engine, `SelectPrompt`, `StaticChoices`, `NewHintBarView`
- `pkg/tui/wizard` -- wizard engine, `SelectPrompt`, `StaticChoices`
- `pkg/tui/bubbletea` -- `Themes`, `ThemeNames()`, `GetThemeName()`, `SetThemeByName()`, `HintStyle()`, `Theme` type
- `charm.land/lipgloss/v2` -- used in `renderThemePreview` for styled color swatches
6 changes: 2 additions & 4 deletions internal/verda-cli/cmd/settings/theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ func selectThemeWizard(cmd *cobra.Command, f cmdutil.Factory, ioStreams cmdutil.
}

flow := &wizard.Flow{
Name: "theme-select",
Layout: []wizard.ViewDef{
{ID: "hints", View: wizard.NewHintBarView(wizard.WithHintStyle(bubbletea.HintStyle()))},
},
Name: "theme-select",
Layout: []wizard.ViewDef{},
Steps: []wizard.Step{
{
Name: "theme",
Expand Down
14 changes: 6 additions & 8 deletions internal/verda-cli/cmd/vm/wizard.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"strings"

"github.com/verda-cloud/verda-cli/pkg/tui"
"github.com/verda-cloud/verda-cli/pkg/tui/bubbletea"
"github.com/verda-cloud/verda-cli/pkg/tui/wizard"
"github.com/verda-cloud/verdacloud-sdk-go/pkg/verda"

Expand Down Expand Up @@ -169,14 +168,13 @@ func buildCreateFlow(ctx context.Context, getClient clientFunc, opts *createOpti
)
}

layout := []wizard.ViewDef{
{ID: "hints", View: wizard.NewHintBarView(wizard.WithHintStyle(bubbletea.HintStyle()))},
}
// Non-nil: a nil Layout selects the default progress view.
layout := []wizard.ViewDef{}
if mode == WizardModeDeploy {
layout = append([]wizard.ViewDef{
{ID: "progress", View: wizard.NewProgressView(wizard.WithProgressPercent())},
{ID: "summary", View: newSummaryView(ctx, getClient, cache, opts)},
}, layout...)
layout = append(layout,
wizard.ViewDef{ID: "progress", View: wizard.NewProgressView(wizard.WithProgressPercent())},
wizard.ViewDef{ID: "summary", View: newSummaryView(ctx, getClient, cache, opts)},
)
}

return &wizard.Flow{
Expand Down
13 changes: 13 additions & 0 deletions internal/verda-cli/cmd/vm/wizard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,16 @@ func TestBuildCreateFlowSpotSkipsContract(t *testing.T) {
t.Errorf("expected hostname=spot-vm, got %q", opts.Hostname)
}
}

func TestBuildCreateFlowHasNoExtraHintBar(t *testing.T) {
t.Parallel()
errClient := func() (*verda.Client, error) { return nil, errors.New("no client in test") }
for _, mode := range []WizardMode{WizardModeDeploy, WizardModeTemplate} {
flow := buildCreateFlow(context.Background(), errClient, &createOptions{}, mode)
for _, def := range flow.Layout {
if _, ok := def.View.(*wizard.HintBarView); ok {
t.Fatalf("mode %v: view %q duplicates the wizard composite's hint bar", mode, def.ID)
}
}
}
}
28 changes: 26 additions & 2 deletions pkg/tui/bubbletea/multiselect.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type multiSelectModel struct {
max int
minErr func(min int) string // resolved: caller override or library default
maxErr func(max int) string // resolved: caller override or library default
backItem bool // last choice is a back action, not a selectable value
showHints bool
customHints []string // nil = derive from bindings
bindings []KeyBinding[multiSelectModel] // resolved (defaults + overrides + extras)
Expand Down Expand Up @@ -101,6 +102,9 @@ func DefaultMultiSelectBindings() []KeyBinding[multiSelectModel] {
return nil, true
}
idx := m.matched[m.cursor]
if m.isBack(idx) {
return nil, true
}
if m.selected[idx] {
delete(m.selected, idx)
m.err = ""
Expand Down Expand Up @@ -139,6 +143,10 @@ func DefaultMultiSelectBindings() []KeyBinding[multiSelectModel] {
Match: MatchKey(tea.KeyEnter),
Label: func(*multiSelectModel) string { return "enter confirm" },
Handle: func(m *multiSelectModel, _ tea.KeyPressMsg) (tea.Cmd, bool) {
if len(m.matched) > 0 && m.isBack(m.matched[m.cursor]) {
m.aborted = true
return func() tea.Msg { return GoBackMsg{} }, true
}
if m.min > 0 && len(m.selected) < m.min {
m.err = m.minErr(m.min)
return nil, true
Expand Down Expand Up @@ -207,7 +215,7 @@ func newMultiSelectModel(prompt string, choices []string, cfg tui.MultiSelectCon
}
selected := make(map[int]bool)
for _, idx := range cfg.Defaults {
if idx >= 0 && idx < len(choices) {
if idx >= 0 && idx < len(choices) && (!cfg.BackItem || idx != len(choices)-1) {
selected[idx] = true
}
}
Expand Down Expand Up @@ -247,12 +255,17 @@ func newMultiSelectModel(prompt string, choices []string, cfg tui.MultiSelectCon
max: cfg.Max,
minErr: minErr,
maxErr: maxErr,
backItem: cfg.BackItem,
showHints: cfg.ShowHints,
customHints: cfg.Hints,
bindings: bindings,
}
}

func (m *multiSelectModel) isBack(idx int) bool {
return m.backItem && idx == len(m.choices)-1
}

func (m *multiSelectModel) refilter() {
m.matched = refilter(m.filter, m.choices, m.matched)
m.cursor = 0
Expand Down Expand Up @@ -284,7 +297,7 @@ func (m *multiSelectModel) moveDown() {
func (m *multiSelectModel) toggleAll() {
allSelected := true
for _, idx := range m.matched {
if !m.selected[idx] {
if !m.isBack(idx) && !m.selected[idx] {
allSelected = false
break
}
Expand All @@ -295,6 +308,9 @@ func (m *multiSelectModel) toggleAll() {
}
} else {
for _, idx := range m.matched {
if m.isBack(idx) {
continue
}
if m.max > 0 && len(m.selected) >= m.max {
m.err = m.maxErr(m.max)
return
Expand Down Expand Up @@ -375,6 +391,14 @@ func (m multiSelectModel) View() tea.View {
if i == m.cursor {
cur = cursorStyle.Render("> ")
}
if m.isBack(idx) {
label := dimStyle.Render(m.choices[idx])
if i == m.cursor {
label = selectedStyle.Render(m.choices[idx])
}
fmt.Fprintf(&b, " %s %s\n", cur, label)
continue
}
check := uncheckStyle.Render("[ ]")
label := dimStyle.Render(m.choices[idx])
if m.selected[idx] {
Expand Down
49 changes: 49 additions & 0 deletions pkg/tui/bubbletea/multiselect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,3 +748,52 @@ func TestMultiSelectModel_ViewShowsError(t *testing.T) {
t.Errorf("view should show min error, got:\n%s", view)
}
}

func TestMultiSelectModel_BackItem(t *testing.T) {
newBack := func() multiSelectModel {
return newMS([]string{"a", "b", "← Back"}, func(c *tui.MultiSelectConfig) { c.BackItem = true })
}

t.Run("select-all skips back", func(t *testing.T) {
m := msCtrl(newBack(), 'a')
if len(m.selected) != 2 || m.selected[2] {
t.Errorf("selected = %v, want only indices 0 and 1", m.selected)
}
m = msCtrl(m, 'a')
if len(m.selected) != 0 {
t.Errorf("second ctrl+a should deselect, selected = %v", m.selected)
}
})

t.Run("space on back is a no-op", func(t *testing.T) {
m := newBack()
m.cursor = 2
m = msKey(m, tea.KeyPressMsg{Code: tea.KeySpace, Text: " "})
if m.selected[2] {
t.Error("back row must not be selectable")
}
})

t.Run("enter on back goes back", func(t *testing.T) {
m := newBack()
m.cursor = 2
updated, cmd := m.Update(tea.KeyPressMsg{Code: tea.KeyEnter})
m = updated.(multiSelectModel)
if m.done {
t.Fatal("enter on back must not complete the prompt")
}
if cmd == nil {
t.Fatal("expected a go-back command")
}
if _, ok := cmd().(GoBackMsg); !ok {
t.Fatalf("expected GoBackMsg, got %T", cmd())
}
})

t.Run("back renders without a checkbox", func(t *testing.T) {
view := newBack().View().Content
if strings.Count(view, "[ ]") != 2 {
t.Errorf("want checkboxes for the two real rows only:\n%s", view)
}
})
}
20 changes: 19 additions & 1 deletion pkg/tui/bubbletea/textinput.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"charm.land/bubbles/v2/textinput"
tea "charm.land/bubbletea/v2"
"charm.land/lipgloss/v2"

"github.com/verda-cloud/verda-cli/pkg/tui"
)
Expand Down Expand Up @@ -109,6 +110,7 @@ func newTextInputModel(prompt string, cfg tui.TextInputConfig) textInputModel {
ti.Placeholder = cfg.Placeholder
ti.SetValue(cfg.Default)
ti.Focus()
syncPlaceholderWidth(&ti)

defaults := ApplyBindingOverrides(DefaultTextInputBindings(), cfg.RelabelByID, cfg.HiddenByID)
var bindings []KeyBinding[textInputModel]
Expand Down Expand Up @@ -141,12 +143,28 @@ func (m textInputModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
}

before := m.textInput.Value()
var cmd tea.Cmd
m.textInput, cmd = m.textInput.Update(msg)
m.err = nil
if m.textInput.Value() != before {
m.err = nil
syncPlaceholderWidth(&m.textInput)
}
return m, cmd
}

// syncPlaceholderWidth: bubbles renders only the first rune of a placeholder
// while Width is 0, so give an empty input the placeholder's width and leave
// typed text unbounded.
func syncPlaceholderWidth(ti *textinput.Model) {
if ti.Value() == "" {
ti.SetWidth(lipgloss.Width(ti.Placeholder))
return
}
ti.SetWidth(0)
ti.SetCursor(ti.Position()) // recompute scroll offsets computed under the narrow width
}

// Hints derives key hints from the resolved bindings.
func (m textInputModel) Hints() []string {
return HintsFor(&m, m.bindings)
Expand Down
Loading