Skip to content

Commit

Permalink
docs: add small code example of embedding form in parent model
Browse files Browse the repository at this point in the history
  • Loading branch information
maaslalani committed Nov 13, 2023
1 parent cbb42b5 commit 15adda4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,13 @@ While you can use `huh` as a replacement to Bubble Tea in many applications
where you only need to prompt the user for input. You can embed `huh` forms in
Bubble Tea applications and use the form as a [Bubble][bubbles].

```go
type Model struct {
// embed form in parent model, use as bubble.
form *huh.Form
}
```

See [the Bubble Tea example][example] for how to embed `huh` forms in [Bubble
Tea][tea] applications for more advanced use cases.

Expand Down
6 changes: 3 additions & 3 deletions examples/bubbletea/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Model struct {
form *huh.Form
}

func NewModel() *Model {
func NewModel() Model {
var m Model
m.class = "Warrior"
m.level = "1"
Expand All @@ -39,14 +39,14 @@ func NewModel() *Model {
)

m.form = f
return &m
return m
}

func (m Model) Init() tea.Cmd {
return m.form.Init()
}

func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
Expand Down

0 comments on commit 15adda4

Please sign in to comment.