input prompter improvements#98
Open
skarim wants to merge 5 commits into
Open
Conversation
276321f to
5531d74
Compare
f105d53 to
9a6a247
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves interactive text input prompting in gh-stack by introducing an editable prefilled input experience (instead of showing defaults in parentheses), and wiring a new test hook to mock text input prompts. It also tweaks the “What’s next” init output to display the stack chain with left-pointing arrows.
Changes:
- Added
Config.InputFnto allow tests to mock freeform text input prompts. - Implemented
inputWithPrefilland switchedinit,add, andsubmitPR-title prompts to use editable prefill text. - Updated init “Created stack” chain formatting (
main ← branch) and adjusted tests accordingly.
Show a summary per file
| File | Description |
|---|---|
| internal/config/config.go | Adds InputFn hook to Config for test-time prompt mocking. |
| cmd/utils.go | Adds inputWithPrefill helper using rune-reader raw input + ANSI coloring. |
| cmd/submit.go | Uses inputWithPrefill for PR title prompting (interactive, non---auto). |
| cmd/init.go | Uses inputWithPrefill for prefix/branch prompts; changes init chain arrow direction. |
| cmd/init_test.go | Updates expectation for new main ← my-feature chain rendering. |
| cmd/add.go | Uses inputWithPrefill for interactive branch naming with prefix prefill. |
| cmd/add_test.go | Adds tests asserting prompt defaults/prefix prefill behavior for add. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (2)
cmd/add.go:168
- With a non-empty prefix, the default prefill is
prefix + "/". If the user accepts the prefill without adding a suffix (or deletes the suffix), the branch name can end up asprefix/, which is not a valid git ref name. Please add validation to reject names that end with "/" (and ideally validate the ref name before callinggit.CreateBranch).
// Pre-fill the prompt with the prefix so the user can see
// (and optionally edit) the full branch name.
prefill := ""
if s.Prefix != "" {
prefill = s.Prefix + "/"
}
for {
input, err := inputWithPrefill(cfg, "Enter a name for the new branch:", prefill)
if err != nil {
if isInterruptError(err) {
printInterrupt(cfg)
return ErrSilent
}
return fmt.Errorf("could not read branch name: %w", err)
}
if input == "" {
cfg.Warningf("branch name cannot be empty, please try again")
continue
}
branchName = input
break
cmd/init.go:455
- Similar to
cmd/add.go, whenprefix != ""the prefill becomesprefix + "/", which makes it easy for the user to submitprefix/as the full branch name. Since the only validation isbranchName == "", this can allow an invalid ref name through until branch creation fails. Add validation to reject trailing-slash names (and ideally rungit.ValidateRefNameon the final branch name).
prefill := ""
prompt := "What's the name of the first branch:"
if prefix != "" {
prompt = "Enter a name for the first branch:"
prefill = prefix + "/"
}
branchName, err := inputWithPrefill(cfg, prompt, prefill)
if err != nil {
if isInterruptError(err) {
printInterrupt(cfg)
return "", ErrSilent
}
cfg.Errorf("failed to read branch name: %s", err)
return "", ErrSilent
}
branchName = strings.TrimSpace(branchName)
if branchName == "" {
cfg.Errorf("branch name cannot be empty")
return "", ErrInvalidArgs
}
return branchName, nil
- Files reviewed: 7/7 changed files
- Comments generated: 4
5531d74 to
6daa31f
Compare
9a6a247 to
6118a59
Compare
6118a59 to
39f3375
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Improve input prompts with inline prefix prefill and colored text
Previously, when
gh stack addorgh stack initprompted for a branch name with a prefix configured, the prefix was mentioned parenthetically in the prompt message (e.g. "will be prefixed with feat/") and silently prepended to whatever the user typed. This made it hard to see or edit the full branch name, and easy to accidentally double-prefix.This PR introduces an
inputWithPrefillhelper that places the prefix directly in the editable input field (e.g. the cursor starts afterfeat/), so the user can see, append to, or modify the full branch name in-place. The user's typed text is rendered in cyan for visual distinction from the prompt.Changes:
inputWithPrefill()tocmd/utils.gousingterminal.RuneReader.ReadLineWithDefaultto render editable prefill text with cyan coloring viamgutz/ansiInputFnhook toconfig.Config, following the existingSelectFn/ConfirmFnpattern, for test injection of text input responsescmd/add.goto pre-fill the prefix in the branch name prompt and use the raw input as the branch name (no silent prepend)cmd/init.go(promptBranchName) to useinputWithPrefillwith the prefix pre-filled, removing the separate "will be prefixed with" message and the post-hoc prefix concatenationcmd/submit.goPR title prompt to useinputWithPrefillfor consistent styling across all input promptsprintWhatsNextfrom→to←to correctly reflect the base-branch relationship (main ← branch1 ← branch2)Tests:
TestAdd_PromptPrefillsPrefix— verifies prefix/ is passed as the default value and the full input is used as the branch nameTestAdd_PromptNoPrefixEmptyDefault— verifies empty default when no prefix is configuredTestAdd_PromptUserModifiesPrefix— verifies user can replace the pre-filled prefix entirely and the verbatim input is usedStack created with GitHub Stacks CLI • Give Feedback 💬