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

Minimise quit state checking in help example #1252

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
14 changes: 7 additions & 7 deletions examples/help/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ type model struct {
help help.Model
inputStyle lipgloss.Style
lastKey string
quitting bool
}

func newModel() model {
Expand Down Expand Up @@ -104,19 +103,14 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case key.Matches(msg, m.keys.Help):
m.help.ShowAll = !m.help.ShowAll
case key.Matches(msg, m.keys.Quit):
m.quitting = true
return m, tea.Quit
return quitModel{}, tea.Quit
}
}

return m, nil
}

func (m model) View() string {
if m.quitting {
return "Bye!\n"
}

var status string
if m.lastKey == "" {
status = "Waiting for input..."
Expand All @@ -130,6 +124,12 @@ func (m model) View() string {
return "\n" + status + strings.Repeat("\n", height) + helpView
}

type quitModel struct{}

func (m quitModel) Init() tea.Cmd { return nil }
func (m quitModel) View() string { return "Bye!\n" }
func (m quitModel) Update(tea.Msg) (tea.Model, tea.Cmd) { return m, nil }

func main() {
if os.Getenv("HELP_DEBUG") != "" {
f, err := tea.LogToFile("debug.log", "help")
Expand Down