feat: add PromptColor setting for customisable shell prompt colour#709
Open
MattieTK wants to merge 2 commits intocharmbracelet:mainfrom
Open
feat: add PromptColor setting for customisable shell prompt colour#709MattieTK wants to merge 2 commits intocharmbracelet:mainfrom
MattieTK wants to merge 2 commits intocharmbracelet:mainfrom
Conversation
3 tasks
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>
de78b5e to
9118167
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.
Summary
Adds a
Set PromptColorsetting that lets users change the colour of VHS's default prompt across all supported shells.Syntax
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:
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/Showsequence, 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
#5B56E0and 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"Aesthetic clash: When users style their recordings with coloured margins or borders, the fixed purple prompt conflicts with the chosen palette:
Set MarginFill "#FF6B2B"With
Set PromptColorAdding a single line to the tape fixes both problems:
Set Theme "Ocean"Set Theme "Fairyfloss"Set PromptColor "#00FF88"Set PromptColor "#FF857A"Set MarginFill "#FF6B2B"Set PromptColor "#FF6B2B"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 theShellConfig()refactoring introduced here.How it works
ShellConfig(name, promptColor)replaces the old staticShellsmap entries. Instead of hardcodedShell{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.Colorfor PowerShell).hexToRGB()parses hex colour strings (with or without#) to RGB components for shells that need numeric values.Evaluator integration:
Set PromptColoris processed in the same early pass asSet Shell, before the tty is started. This was the key insight that cmd: add support forENVcommand #469 missed – the colour needs to be known beforebuildTtyCmdruns, so it's handled alongside Shell in the evaluator's pre-start loop.Shell support
38;2;R;G;Bin PS1%F{#RRGGBB}in PROMPT#prefixset_color RRGGBBin fish_prompt#prefixSystem.Drawing.Color::FromArgb(R,G,B)promptcommand has no colour codes; keeps default38;2;R;G;Bin PROMPT_COMMAND38;2;R;G;Bin PROMPTFollow-up: Set Prompt (#710)
The
ShellConfig()refactoring here also enables customising the prompt symbol. #710 demonstrates this by adding aSet Promptsetting that accepts any string:That PR adds a single parameter to
ShellConfig()– a direct payoff of the structural work in this PR.Related discussions
ENVcommand #469 – PR that attempted prompt customisation viaEnv PROMPT, removed as hackyTest plan
TestHexToRGB: hex parsing with#, without#, invalid length, empty stringTestShellConfigReturnsNonNil: all 9 shells return valid configsTestShellConfigCustomColor: custom colour (#FF8000) correctly embedded in bash RGB and zsh hexTestShellConfigDefaultColor: default colour produces original RGB valuesTestShellConfigUnknownShell: unknown shell returns nilgo test ./...)Note
This PR was authored with AI assistance (Claude Code).