Skip to content

input prompter improvements#98

Open
skarim wants to merge 5 commits into
skarim/rebase-preserve-datefrom
skarim/prompter-improvements
Open

input prompter improvements#98
skarim wants to merge 5 commits into
skarim/rebase-preserve-datefrom
skarim/prompter-improvements

Conversation

@skarim
Copy link
Copy Markdown
Collaborator

@skarim skarim commented May 18, 2026

Improve input prompts with inline prefix prefill and colored text

Previously, when gh stack add or gh stack init prompted 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 inputWithPrefill helper that places the prefix directly in the editable input field (e.g. the cursor starts after feat/), 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:

  • Add inputWithPrefill() to cmd/utils.go using terminal.RuneReader.ReadLineWithDefault to render editable prefill text with cyan coloring via mgutz/ansi
  • Add InputFn hook to config.Config, following the existing SelectFn/ConfirmFn pattern, for test injection of text input responses
  • Update cmd/add.go to pre-fill the prefix in the branch name prompt and use the raw input as the branch name (no silent prepend)
  • Update cmd/init.go (promptBranchName) to use inputWithPrefill with the prefix pre-filled, removing the separate "will be prefixed with" message and the post-hoc prefix concatenation
  • Update cmd/submit.go PR title prompt to use inputWithPrefill for consistent styling across all input prompts
  • Fix arrow direction in printWhatsNext from 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 name
  • TestAdd_PromptNoPrefixEmptyDefault — verifies empty default when no prefix is configured
  • TestAdd_PromptUserModifiesPrefix — verifies user can replace the pre-filled prefix entirely and the verbatim input is used

Stack created with GitHub Stacks CLIGive Feedback 💬

@skarim skarim force-pushed the skarim/rebase-preserve-date branch from 276321f to 5531d74 Compare May 22, 2026 16:26
@skarim skarim force-pushed the skarim/prompter-improvements branch from f105d53 to 9a6a247 Compare May 22, 2026 16:26
@skarim skarim marked this pull request as ready for review May 23, 2026 21:35
Copilot AI review requested due to automatic review settings May 23, 2026 21:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.InputFn to allow tests to mock freeform text input prompts.
  • Implemented inputWithPrefill and switched init, add, and submit PR-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 as prefix/, which is not a valid git ref name. Please add validation to reject names that end with "/" (and ideally validate the ref name before calling git.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, when prefix != "" the prefill becomes prefix + "/", which makes it easy for the user to submit prefix/ as the full branch name. Since the only validation is branchName == "", this can allow an invalid ref name through until branch creation fails. Add validation to reject trailing-slash names (and ideally run git.ValidateRefName on 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

Comment thread cmd/utils.go
Comment thread cmd/utils.go Outdated
Comment thread cmd/add.go
Comment thread cmd/init.go
@skarim skarim force-pushed the skarim/rebase-preserve-date branch from 5531d74 to 6daa31f Compare May 23, 2026 22:05
@skarim skarim force-pushed the skarim/prompter-improvements branch from 9a6a247 to 6118a59 Compare May 23, 2026 22:05
@skarim skarim force-pushed the skarim/prompter-improvements branch from 6118a59 to 39f3375 Compare May 23, 2026 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants