feat(options): template expressions in segment options#7455
Open
MO2k4 wants to merge 8 commits intoJanDeDobbeleer:mainfrom
Open
feat(options): template expressions in segment options#7455MO2k4 wants to merge 8 commits intoJanDeDobbeleer:mainfrom
MO2k4 wants to merge 8 commits intoJanDeDobbeleer:mainfrom
Conversation
Add SetContext/getContext for storing template context on options.Map
via a sentinel key. Add resolveTemplate helper that checks for {{
syntax and resolves via template.Render before type conversion.
…ccessors
Each typed accessor now checks for string values containing {{ template
syntax and resolves them via template.Render before type conversion.
On failure, the default value is returned.
…check - Extract setupTemplateTestEnv() to deduplicate mock environment setup repeated across 6 test functions (~100 lines removed) - Remove redundant strings.Contains check in Color() since resolveTemplate() already performs that check
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
Int,Float64,Bool,Color) now accept Go template expressions as string values, resolved at render time using the segment writer as contextmax_width = '{{ sub .TerminalWidth 30 }}'to size a path based on terminal widthgetMaxWidthdrops ~20 lines of manual template handling in favor of the new template-awareInt()accessormax_depthandmixed_thresholdacceptstringalongsideintegerHow it works
After
Init, the segment writer is stored as a template context in the options map. When a typed accessor finds a string value with{{ }}, it resolves the template before parsing. If resolution or parsing fails, the default value is used.Test plan
go test ./segments/options/— template resolution tests for Int, Float64, Bool, Colorgo test ./segments/ -run TestGetMaxWidth— path segment uses template-aware Int() correctlyCloses #7243