feat(powerline): add leading_powerline_symbol

This commit is contained in:
Jan De Dobbeleer 2024-05-23 09:49:47 +02:00 committed by Jan De Dobbeleer
parent 44da6a660e
commit be47940d00
4 changed files with 94 additions and 49 deletions

View file

@ -176,38 +176,70 @@ func (b *Block) writeSeparator(final bool) {
if isPreviousDiamond {
b.adjustTrailingDiamondColorOverrides()
}
if isPreviousDiamond && isCurrentDiamond && len(b.activeSegment.LeadingDiamond) == 0 {
b.writer.Write(ansi.Background, ansi.ParentBackground, b.previousActiveSegment.TrailingDiamond)
return
}
if isPreviousDiamond && len(b.previousActiveSegment.TrailingDiamond) > 0 {
b.writer.Write(ansi.Transparent, ansi.ParentBackground, b.previousActiveSegment.TrailingDiamond)
}
isPowerline := b.activeSegment.isPowerline()
shouldOverridePowerlineLeadingSymbol := func() bool {
if !isPowerline {
return false
}
if isPowerline && len(b.activeSegment.LeadingPowerlineSymbol) == 0 {
return false
}
if b.previousActiveSegment != nil && b.previousActiveSegment.isPowerline() {
return false
}
return true
}
if shouldOverridePowerlineLeadingSymbol() {
b.writer.Write(ansi.Transparent, ansi.Background, b.activeSegment.LeadingPowerlineSymbol)
return
}
resolvePowerlineSymbol := func() string {
var symbol string
if b.activeSegment.isPowerline() {
symbol = b.activeSegment.PowerlineSymbol
} else if b.previousActiveSegment != nil && b.previousActiveSegment.isPowerline() {
symbol = b.previousActiveSegment.PowerlineSymbol
if isPowerline {
return b.activeSegment.PowerlineSymbol
}
return symbol
if b.previousActiveSegment != nil && b.previousActiveSegment.isPowerline() {
return b.previousActiveSegment.PowerlineSymbol
}
return ""
}
symbol := resolvePowerlineSymbol()
if len(symbol) == 0 {
return
}
bgColor := ansi.Background
if final || !b.activeSegment.isPowerline() {
if final || !isPowerline {
bgColor = ansi.Transparent
}
if b.activeSegment.style() == Diamond && len(b.activeSegment.LeadingDiamond) == 0 {
bgColor = ansi.Background
}
if b.activeSegment.InvertPowerline {
b.writer.Write(b.getPowerlineColor(), bgColor, symbol)
return
}
b.writer.Write(bgColor, b.getPowerlineColor(), symbol)
}

View file

@ -24,6 +24,7 @@ type Segment struct {
Tips []string `json:"tips,omitempty" toml:"tips,omitempty"`
Style SegmentStyle `json:"style,omitempty" toml:"style,omitempty"`
PowerlineSymbol string `json:"powerline_symbol,omitempty" toml:"powerline_symbol,omitempty"`
LeadingPowerlineSymbol string `json:"leading_powerline_symbol,omitempty" toml:"leading_powerline_symbol,omitempty"`
InvertPowerline bool `json:"invert_powerline,omitempty" toml:"invert_powerline,omitempty"`
Foreground string `json:"foreground,omitempty" toml:"foreground,omitempty"`
ForegroundTemplates template.List `json:"foreground_templates,omitempty" toml:"foreground_templates,omitempty"`

View file

@ -578,7 +578,13 @@
"type": "string",
"title": "Powerline Symbol",
"description": "https://ohmyposh.dev/docs/configuration/segment#powerline-symbol",
"default": "\uE0B0"
"default": "\ue0b0"
},
"leading_powerline_symbol": {
"type": "string",
"title": "Leading Powerline Symbol",
"description": "https://ohmyposh.dev/docs/configuration/segment#powerline-symbol",
"default": "\ue0d7"
},
"invert_powerline": {
"type": "boolean",

View file

@ -34,10 +34,11 @@ understand how to configure a segment.
```
| Name | Type | Description |
| ---------------------- | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| -------------------------- | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `type` | `string` | takes the `string` value referencing which segment logic it needs to run (see [segments][segments] for possible values) |
| `style` | `string` | see [Style][style] below. Possible values:<ul><li>`powerline`</li><li>`plain`</li><li>`diamond`</li><li>`accordion`</li><li>a go [text/template][go-text-template] [template][templates] resolving to the above values</li></ul> |
| `powerline_symbol` | `string` | character to use when `"style": "powerline"` |
| `leading_powerline_symbol` | `string` | when `"style": "powerline"` we use an ANSI hack to invert the `powerline_symbol` to create a transparent glyph. This gives the best alignment, but might not work in every terminal. If you see black elements at the start of powerline segments, you can set this to the "opening" version of the `powerline_symbol`. |
| `invert_powerline` | `boolean` | if `true` swaps the foreground and background colors. Can be useful when the character you want does not exist in the perfectly mirrored variant for example - defaults to `false` |
| `leading_diamond` | `string` | character to use at the start of the segment. Will take the background color of the segment as its foreground color |
| `trailing_diamond` | `string` | character to use at the end of the segment. Will take the background color of the segment as its foreground color |
@ -66,6 +67,11 @@ What started it all for us. Makes use of a single symbol (`powerline_symbol`) to
background color of the previous segment (or transparent if none) and the foreground of the current one (or transparent
if we're at the last segment). Expects segments to have a colored background, else there little use for this one.
When you see black triangles (or other characters depending on the `powerline_symbol` you use) at the start of a segment,
you can set `leading_powerline_symbol` to the "opening" version of the `powerline_symbol`.
This will not use the inverted ANSI hack we have in place as that's not supported in every terminal. You might need to tweak
your font settings to get the best alignment.
### Plain
Simple. Colored text on a transparent background. Make sure to set `foreground` for maximum enjoyment.