-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new input model, use in projects step (#30)
* add new text input mmodel * add new input step to project model, update wizard step to handle that update * add note about error handling; * remove debugging stmt * store projects in memory so we can mimic adding new ones * refetch projects if we go back to that step from environment step * make fetching resources more generic * add/update comments
- Loading branch information
1 parent
c4dc7d0
commit fbc9d0f
Showing
3 changed files
with
137 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package setup | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/charmbracelet/bubbles/textinput" | ||
tea "github.com/charmbracelet/bubbletea" | ||
) | ||
|
||
type inputModel struct { | ||
textInput textinput.Model | ||
done bool | ||
title string | ||
err error | ||
} | ||
|
||
func newTextInputModel(placeholder, title string) inputModel { | ||
ti := textinput.New() | ||
ti.Placeholder = placeholder | ||
ti.Focus() | ||
ti.CharLimit = 156 | ||
ti.Width = 20 | ||
|
||
return inputModel{ | ||
title: title, | ||
textInput: ti, | ||
err: nil, | ||
} | ||
} | ||
|
||
func (m inputModel) Init() tea.Cmd { | ||
return textinput.Blink | ||
} | ||
|
||
func (m inputModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | ||
var cmd tea.Cmd | ||
|
||
switch msg := msg.(type) { | ||
case tea.KeyMsg: | ||
switch msg.Type { | ||
case tea.KeyEnter: | ||
m.done = true | ||
return m, nil | ||
case tea.KeyCtrlC, tea.KeyEsc: | ||
return m, tea.Quit | ||
} | ||
|
||
// TODO: Handle errors | ||
} | ||
|
||
m.textInput, cmd = m.textInput.Update(msg) | ||
return m, cmd | ||
} | ||
|
||
func (m inputModel) View() string { | ||
return fmt.Sprintf( | ||
"%s\n\n%s\n\n%s", | ||
m.title, | ||
m.textInput.View(), | ||
"(esc to quit)", | ||
) + "\n" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters