Skip to content

Commit

Permalink
feat: use tab to toggle, add final step (#50)
Browse files Browse the repository at this point in the history
* Make styling consistent

* Update title punctuation and capitalization

* Add border around rendered markdown

* use tab to toggle flag, add final congrats step

* update wizard

* quit when we've run out of models

* no emojis :(

* add placeholder cta to final step

* different placeholder text

---------

Co-authored-by: Danny Olson <dolson@launchdarkly.com>
  • Loading branch information
k3llymariee and dbolson authored Mar 21, 2024
1 parent 73ef41e commit 33a447d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
6 changes: 3 additions & 3 deletions internal/setup/flag_toggle.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (m flagToggleModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch {
case key.Matches(msg, keys.Enter):
case key.Matches(msg, keys.Toggle):
m.enabled = !m.enabled
}
}
Expand All @@ -33,13 +33,13 @@ func (m flagToggleModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

func (m flagToggleModel) View() string {
var furtherInstructions string
title := "Toggle your feature flag!"
title := "Toggle your feature flag (press tab)"
toggle := "OFF"
bgColor := "#646a73"
margin := 1
if m.enabled {
bgColor = "#3d9c51"
furtherInstructions = "\n\nCheck your [browser|application logs] to see the change."
furtherInstructions = "\n\nCheck your [browser|application logs] to see the change!"
margin = 2
toggle = "ON"
}
Expand Down
21 changes: 17 additions & 4 deletions internal/setup/wizard.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/charmbracelet/bubbles/key"
tea "github.com/charmbracelet/bubbletea"
"github.com/muesli/reflow/wordwrap"
)

// TODO: we may want to rename this for clarity
Expand Down Expand Up @@ -102,7 +103,10 @@ func (m WizardModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case flagToggleStep:
updatedModel, _ := m.steps[flagToggleStep].Update(msg)
m.steps[flagToggleStep] = updatedModel
m.currStep += 1
default:
return m, tea.Quit

}
case key.Matches(msg, keys.Back):
// only go back if not on the first step
Expand Down Expand Up @@ -130,14 +134,19 @@ func (m WizardModel) View() string {
return fmt.Sprintf("ERROR: %s", m.err)
}

if m.currStep > flagToggleStep {
return wordwrap.String("\nCongratulations! You’ve just used feature flags to control how your application works, without having to rebuild or redeploy your application.\n\nNow that you’re set up with your first feature flag, let’s make it easier to manage your flags collaboratively with your team. <Instructions will go here>", m.width)
}

return fmt.Sprintf("\nStep %d of %d\n"+m.steps[m.currStep].View(), m.currStep+1, len(m.steps))
}

type keyMap struct {
Back key.Binding
Enter key.Binding
Help key.Binding
Quit key.Binding
Back key.Binding
Enter key.Binding
Help key.Binding
Quit key.Binding
Toggle key.Binding
}

var keys = keyMap{
Expand All @@ -157,4 +166,8 @@ var keys = keyMap{
key.WithKeys("ctrl+c", "q"),
key.WithHelp("q", "quit"),
),
Toggle: key.NewBinding(
key.WithKeys("tab"),
key.WithHelp("tab", "toggle"),
),
}

0 comments on commit 33a447d

Please sign in to comment.