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

Fix some linting of filterapi example #153

Merged
merged 1 commit into from
Oct 9, 2023
Merged
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
9 changes: 6 additions & 3 deletions examples/filterapi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func NewModel() Model {
table.NewColumn(columnKeyAuthor, "Author", 13).WithFiltered(true),
table.NewColumn(columnKeyDescription, "Description", 50),
}

return Model{
table: table.
New(columns).
Expand Down Expand Up @@ -74,16 +75,18 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// global
if msg.String() == "ctrl+c" {
cmds = append(cmds, tea.Quit)

return m, tea.Batch(cmds...)
}
// event to filter
if m.filterTextInput.Focused() {
if msg.String() == "enter" {
m.filterTextInput.Blur()
} else {
m.filterTextInput, cmd = m.filterTextInput.Update(msg)
m.filterTextInput, _ = m.filterTextInput.Update(msg)
}
m.table = m.table.WithFilterInput(m.filterTextInput)

return m, tea.Batch(cmds...)
}

Expand All @@ -98,7 +101,6 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.table, cmd = m.table.Update(msg)
cmds = append(cmds, cmd)
}

}

return m, tea.Batch(cmds...)
Expand All @@ -108,7 +110,8 @@ func (m Model) View() string {
body := strings.Builder{}

body.WriteString("A filtered simple default table\n" +
"Currently filter by Title and Author, press / + letters to start filtering, and escape to clear filter.\nPress q or ctrl+c to quit\n\n")
"Currently filter by Title and Author, press / + letters to start filtering, and escape to clear filter.\n" +
"Press q or ctrl+c to quit\n\n")

body.WriteString(m.filterTextInput.View() + "\n")
body.WriteString(m.table.View())
Expand Down
Loading