Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose input field Messages #477

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion field_confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (c *Confirm) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmds []tea.Cmd

switch msg := msg.(type) {
case updateFieldMsg:
case UpdateFieldMsg:
if ok, hash := c.title.shouldUpdate(); ok {
c.title.bindingsHash = hash
if !c.title.loadFromCache() {
Expand Down
2 changes: 1 addition & 1 deletion field_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func (i *Input) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd

switch msg := msg.(type) {
case updateFieldMsg:
case UpdateFieldMsg:
var cmds []tea.Cmd
if ok, hash := i.title.shouldUpdate(); ok {
i.title.bindingsHash = hash
Expand Down
2 changes: 1 addition & 1 deletion field_multiselect.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func (m *MultiSelect[T]) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

switch msg := msg.(type) {
case updateFieldMsg:
case UpdateFieldMsg:
var fieldCmds []tea.Cmd
if ok, hash := m.title.shouldUpdate(); ok {
m.title.bindingsHash = hash
Expand Down
2 changes: 1 addition & 1 deletion field_note.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (n *Note) Init() tea.Cmd { return nil }
// Update updates the note field.
func (n *Note) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case updateFieldMsg:
case UpdateFieldMsg:
var cmds []tea.Cmd
if ok, hash := n.title.shouldUpdate(); ok {
n.title.bindingsHash = hash
Expand Down
2 changes: 1 addition & 1 deletion field_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func (s *Select[T]) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

switch msg := msg.(type) {
case updateFieldMsg:
case UpdateFieldMsg:
var cmds []tea.Cmd
if ok, hash := s.title.shouldUpdate(); ok {
s.title.bindingsHash = hash
Expand Down
2 changes: 1 addition & 1 deletion field_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (t *Text) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
t.textarea, cmd = t.textarea.Update(msg)
cmds = append(cmds, cmd)
t.accessor.Set(t.textarea.Value())
case updateFieldMsg:
case UpdateFieldMsg:
var cmds []tea.Cmd
if ok, hash := t.placeholder.shouldUpdate(); ok {
t.placeholder.bindingsHash = hash
Expand Down
2 changes: 1 addition & 1 deletion form.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ func (f *Form) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return f, f.CancelCmd
}

case nextFieldMsg:
case NextFieldMsg:
// Form is progressing to the next field, let's save the value of the current field.
field := group.selector.Selected()
f.results[field.GetKey()] = field.GetValue()
Expand Down
22 changes: 11 additions & 11 deletions group.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,33 +157,33 @@ func (g *Group) Errors() []error {
return errs
}

// updateFieldMsg is a message to update the fields of a group that is currently
// UpdateFieldMsg is a message to update the fields of a group that is currently
// displayed.
//
// This is used to update all TitleFunc, DescriptionFunc, and ...Func update
// methods to make all fields dynamically update based on user input.
type updateFieldMsg struct{}
type UpdateFieldMsg struct{}

// nextFieldMsg is a message to move to the next field,
// NextFieldMsg is a message to move to the next field,
//
// each field controls when to send this message such that it is able to use
// different key bindings or events to trigger group progression.
type nextFieldMsg struct{}
type NextFieldMsg struct{}

// prevFieldMsg is a message to move to the previous field.
// PrevFieldMsg is a message to move to the previous field.
//
// each field controls when to send this message such that it is able to use
// different key bindings or events to trigger group progression.
type prevFieldMsg struct{}
type PrevFieldMsg struct{}

// NextField is the command to move to the next field.
func NextField() tea.Msg {
return nextFieldMsg{}
return NextFieldMsg{}
}

// PrevField is the command to move to the previous field.
func PrevField() tea.Msg {
return prevFieldMsg{}
return PrevFieldMsg{}
}

// Init initializes the group.
Expand Down Expand Up @@ -260,7 +260,7 @@ func (g *Group) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
g.selector.Set(i, m.(Field))
cmds = append(cmds, cmd)
}
m, cmd := field.Update(updateFieldMsg{})
m, cmd := field.Update(UpdateFieldMsg{})
g.selector.Set(i, m.(Field))
cmds = append(cmds, cmd)
return true
Expand All @@ -269,9 +269,9 @@ func (g *Group) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.WindowSizeMsg:
g.WithHeight(max(g.height, min(g.fullHeight(), msg.Height-1)))
case nextFieldMsg:
case NextFieldMsg:
cmds = append(cmds, g.nextField()...)
case prevFieldMsg:
case PrevFieldMsg:
cmds = append(cmds, g.prevField()...)
}

Expand Down