Skip to content

feat: add PromptColor setting for customisable shell prompt colour#709

Open
MattieTK wants to merge 2 commits intocharmbracelet:mainfrom
MattieTK:feature/prompt-color-setting
Open

feat: add PromptColor setting for customisable shell prompt colour#709
MattieTK wants to merge 2 commits intocharmbracelet:mainfrom
MattieTK:feature/prompt-color-setting

Conversation

@MattieTK
Copy link
Copy Markdown

@MattieTK MattieTK commented Feb 20, 2026

Summary

Adds a Set PromptColor setting that lets users change the colour of VHS's default prompt across all supported shells.

Syntax

Set PromptColor "#FF8000"    # orange prompt
Set PromptColor "#00FF00"    # green prompt

The default remains #5B56E0 (the existing blue-purple), so existing tapes are unaffected.

Motivation

Prompt customisation is one of the most requested features in VHS. Issue #419 ("How can I change Shell Prompt") has been open since mid-2023 and has driven users to alternative tools:

"I've switched to asciinema at the moment just because of this issue"@ocervell

"This issue is basically forcing my hand to use asciinema"@artob

"Setting PS1 with the Env command has no effect on the prompt for bash"@artob

There was a previous attempt in PR #469 where @Delta456 tried reading os.Getenv("PROMPT") at module init time, but the environment wasn't set yet at that point. @maaslalani removed the hack and noted: "Let's remove this hack for now and keep thinking how to solve PROMPTs."

The current workaround suggested in #419 involves a Hide/Type/Enter/clear/Show sequence, which is fragile and leaves artefacts.

The colour clash problem

VHS already lets users control themes, margins, and window bars – but the prompt colour is hardcoded to #5B56E0 and cannot be adjusted. This creates two problems:

Accessibility: Themes with blue or purple backgrounds make the prompt nearly invisible. The > disappears against backgrounds of similar hue and luminance:

Set Theme "Ocean" Set Theme "Fairyfloss"
Ocean theme – prompt invisible on blue background Fairyfloss theme – prompt lost in purple-grey background

Aesthetic clash: When users style their recordings with coloured margins or borders, the fixed purple prompt conflicts with the chosen palette:

Set MarginFill "#FF6B2B"
Orange margin with clashing purple prompt

With Set PromptColor

Adding a single line to the tape fixes both problems:

Set Theme "Ocean" Set Theme "Fairyfloss"
Set PromptColor "#00FF88" Set PromptColor "#FF857A"
Ocean with green prompt Fairyfloss with pink prompt
Set MarginFill "#FF6B2B"
Set PromptColor "#FF6B2B"
Orange margin with matching orange prompt

Why colour first, not the full prompt?

This PR deliberately limits scope to the prompt colour rather than the full prompt string (symbol, format, etc.). Colour is the simpler case – it doesn't affect prompt width or terminal layout, and the > symbol is consistent across shells. Full prompt symbol customisation is demonstrated in #710 (Set Prompt), which builds directly on the ShellConfig() refactoring introduced here.

How it works

  1. ShellConfig(name, promptColor) replaces the old static Shells map entries. Instead of hardcoded Shell{Env: ..., Command: ...} structs, each shell's configuration is generated dynamically with the chosen colour embedded in the appropriate format (ANSI RGB for bash/osh/nushell/xonsh, hex for zsh/fish, System.Drawing.Color for PowerShell).

  2. hexToRGB() parses hex colour strings (with or without #) to RGB components for shells that need numeric values.

  3. Evaluator integration: Set PromptColor is processed in the same early pass as Set Shell, before the tty is started. This was the key insight that cmd: add support for ENV command #469 missed – the colour needs to be known before buildTtyCmd runs, so it's handled alongside Shell in the evaluator's pre-start loop.

Shell support

Shell Colour format Notes
bash ANSI 38;2;R;G;B in PS1 RGB values from hex
zsh %F{#RRGGBB} in PROMPT Hex without # prefix
fish set_color RRGGBB in fish_prompt Hex without # prefix
PowerShell System.Drawing.Color::FromArgb(R,G,B) RGB values
pwsh Same as PowerShell Same mechanism
cmd.exe Not supported cmd.exe's prompt command has no colour codes; keeps default
nushell ANSI 38;2;R;G;B in PROMPT_COMMAND RGB values
osh Same as bash Shares bash's PS1 format
xonsh ANSI 38;2;R;G;B in PROMPT RGB values

Follow-up: Set Prompt (#710)

The ShellConfig() refactoring here also enables customising the prompt symbol. #710 demonstrates this by adding a Set Prompt setting that accepts any string:

Set PromptColor "#FF8000"
Set Prompt "$"    # bash-style

That PR adds a single parameter to ShellConfig() – a direct payoff of the structural work in this PR.

Related discussions

Test plan

  • TestHexToRGB: hex parsing with #, without #, invalid length, empty string
  • TestShellConfigReturnsNonNil: all 9 shells return valid configs
  • TestShellConfigCustomColor: custom colour (#FF8000) correctly embedded in bash RGB and zsh hex
  • TestShellConfigDefaultColor: default colour produces original RGB values
  • TestShellConfigUnknownShell: unknown shell returns nil
  • Full test suite passes (go test ./...)
  • Manual testing with real tape files

Note

This PR was authored with AI assistance (Claude Code).

@MattieTK MattieTK marked this pull request as ready for review February 20, 2026 07:54
@MattieTK MattieTK requested a review from a team as a code owner February 20, 2026 07:54
@MattieTK MattieTK requested review from meowgorithm and raphamorim and removed request for a team February 20, 2026 07:54
MattieTK and others added 2 commits March 22, 2026 09:46
Add a new Set PromptColor setting that allows users to customize
the shell prompt color via a hex value (e.g., Set PromptColor "#f6821f").

Changes:
- Add PROMPT_COLOR token to token/token.go
- Refactor shell.go to support configurable prompt colors via ShellConfig()
- Add hexToRGB() helper function for color conversion
- Update tty.go to pass prompt color to shell configuration
- Add PromptColor field to Options struct with default #5B56E0
- Add ExecuteSetPromptColor function in command.go
- Update evaluator.go to handle PromptColor before VHS starts

The prompt color is applied to all supported shells (bash, zsh, fish,
nushell, osh, xonsh, powershell, pwsh). The cmdexe shell doesn't support
color customization.
Cover hex parsing edge cases (with/without #, invalid length, empty),
ShellConfig output for all 9 shells, custom colour embedding in bash
and zsh, default colour round-trip, and unknown shell handling.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@MattieTK MattieTK force-pushed the feature/prompt-color-setting branch from de78b5e to 9118167 Compare March 22, 2026 09:47
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.

1 participant