-
Notifications
You must be signed in to change notification settings - Fork 0
Simplify update notification flow #159
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,6 +95,9 @@ func (a App) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | |
| return a, tea.Quit | ||
| } | ||
| if a.pendingInput != nil { | ||
| if a.pendingInput.Vertical { | ||
| return a.handleVerticalPromptKey(msg) | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: the |
||
| if opt := resolveOption(a.pendingInput.Options, msg); opt != nil { | ||
| a.lines = appendLine(a.lines, styledLine{text: formatResolvedInput(*a.pendingInput, opt.Key)}) | ||
| responseCmd := sendInputResponseCmd(a.pendingInput.ResponseCh, output.InputResponse{SelectedKey: opt.Key}) | ||
|
|
@@ -110,7 +113,7 @@ func (a App) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | |
| if a.spinner.Visible() { | ||
| a.spinner = a.spinner.SetText(output.FormatPrompt(msg.Prompt, msg.Options)) | ||
| } else { | ||
| a.inputPrompt = a.inputPrompt.Show(msg.Prompt, msg.Options) | ||
| a.inputPrompt = a.inputPrompt.Show(msg.Prompt, msg.Options, msg.Vertical) | ||
| } | ||
| case spinner.TickMsg: | ||
| var cmd tea.Cmd | ||
|
|
@@ -295,6 +298,35 @@ func (a *App) flushBufferedLines() { | |
| a.bufferedLines = nil | ||
| } | ||
|
|
||
| func (a App) handleVerticalPromptKey(msg tea.KeyMsg) (tea.Model, tea.Cmd) { | ||
| switch msg.Type { | ||
| case tea.KeyUp: | ||
| a.inputPrompt = a.inputPrompt.SetSelectedIndex(a.inputPrompt.SelectedIndex() - 1) | ||
| return a, nil | ||
| case tea.KeyDown: | ||
| a.inputPrompt = a.inputPrompt.SetSelectedIndex(a.inputPrompt.SelectedIndex() + 1) | ||
| return a, nil | ||
| case tea.KeyEnter: | ||
| idx := a.inputPrompt.SelectedIndex() | ||
| if idx >= 0 && idx < len(a.pendingInput.Options) { | ||
| opt := a.pendingInput.Options[idx] | ||
| a.lines = appendLine(a.lines, styledLine{text: formatResolvedInput(*a.pendingInput, opt.Key)}) | ||
| responseCmd := sendInputResponseCmd(a.pendingInput.ResponseCh, output.InputResponse{SelectedKey: opt.Key}) | ||
| a.pendingInput = nil | ||
| a.inputPrompt = a.inputPrompt.Hide() | ||
| return a, responseCmd | ||
| } | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue: this file is generic UI rendering code, it should not know anything about the update logic. |
||
| if opt := resolveOption(a.pendingInput.Options, msg); opt != nil { | ||
| a.lines = appendLine(a.lines, styledLine{text: formatResolvedInput(*a.pendingInput, opt.Key)}) | ||
| responseCmd := sendInputResponseCmd(a.pendingInput.ResponseCh, output.InputResponse{SelectedKey: opt.Key}) | ||
| a.pendingInput = nil | ||
| a.inputPrompt = a.inputPrompt.Hide() | ||
| return a, responseCmd | ||
| } | ||
| return a, nil | ||
| } | ||
|
|
||
| func formatResolvedInput(req output.UserInputRequestEvent, selectedKey string) string { | ||
| formatted := output.FormatPrompt(req.Prompt, req.Options) | ||
| firstLine := strings.Split(formatted, "\n")[0] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: this looks like migration code, is this right?
update_prompt: I think we could ignore the fact that some users previously had this setting one level up in the config. They would just be asked again and in exchange we get rid of some complexity.update_skipped_version: This is introduced in this PR so there is nothing to migrate.In short: can we remove these lines?