mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-21 02:55:37 -08:00
feat(powerline): add leading_powerline_symbol
This commit is contained in:
parent
44da6a660e
commit
be47940d00
|
@ -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)
|
||||
}
|
||||
|
||||
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
|
||||
isPowerline := b.activeSegment.isPowerline()
|
||||
|
||||
shouldOverridePowerlineLeadingSymbol := func() bool {
|
||||
if !isPowerline {
|
||||
return false
|
||||
}
|
||||
return symbol
|
||||
|
||||
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 {
|
||||
if isPowerline {
|
||||
return b.activeSegment.PowerlineSymbol
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
|
@ -20,26 +20,27 @@ import (
|
|||
|
||||
// Segment represent a single segment and it's configuration
|
||||
type Segment struct {
|
||||
Type SegmentType `json:"type,omitempty" toml:"type,omitempty"`
|
||||
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"`
|
||||
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"`
|
||||
Background string `json:"background,omitempty" toml:"background,omitempty"`
|
||||
BackgroundTemplates template.List `json:"background_templates,omitempty" toml:"background_templates,omitempty"`
|
||||
LeadingDiamond string `json:"leading_diamond,omitempty" toml:"leading_diamond,omitempty"`
|
||||
TrailingDiamond string `json:"trailing_diamond,omitempty" toml:"trailing_diamond,omitempty"`
|
||||
Template string `json:"template,omitempty" toml:"template,omitempty"`
|
||||
Templates template.List `json:"templates,omitempty" toml:"templates,omitempty"`
|
||||
TemplatesLogic template.Logic `json:"templates_logic,omitempty" toml:"templates_logic,omitempty"`
|
||||
Properties properties.Map `json:"properties,omitempty" toml:"properties,omitempty"`
|
||||
Interactive bool `json:"interactive,omitempty" toml:"interactive,omitempty"`
|
||||
Alias string `json:"alias,omitempty" toml:"alias,omitempty"`
|
||||
MaxWidth int `json:"max_width,omitempty" toml:"max_width,omitempty"`
|
||||
MinWidth int `json:"min_width,omitempty" toml:"min_width,omitempty"`
|
||||
Filler string `json:"filler,omitempty" toml:"filler,omitempty"`
|
||||
Type SegmentType `json:"type,omitempty" toml:"type,omitempty"`
|
||||
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"`
|
||||
Background string `json:"background,omitempty" toml:"background,omitempty"`
|
||||
BackgroundTemplates template.List `json:"background_templates,omitempty" toml:"background_templates,omitempty"`
|
||||
LeadingDiamond string `json:"leading_diamond,omitempty" toml:"leading_diamond,omitempty"`
|
||||
TrailingDiamond string `json:"trailing_diamond,omitempty" toml:"trailing_diamond,omitempty"`
|
||||
Template string `json:"template,omitempty" toml:"template,omitempty"`
|
||||
Templates template.List `json:"templates,omitempty" toml:"templates,omitempty"`
|
||||
TemplatesLogic template.Logic `json:"templates_logic,omitempty" toml:"templates_logic,omitempty"`
|
||||
Properties properties.Map `json:"properties,omitempty" toml:"properties,omitempty"`
|
||||
Interactive bool `json:"interactive,omitempty" toml:"interactive,omitempty"`
|
||||
Alias string `json:"alias,omitempty" toml:"alias,omitempty"`
|
||||
MaxWidth int `json:"max_width,omitempty" toml:"max_width,omitempty"`
|
||||
MinWidth int `json:"min_width,omitempty" toml:"min_width,omitempty"`
|
||||
Filler string `json:"filler,omitempty" toml:"filler,omitempty"`
|
||||
|
||||
Enabled bool `json:"-" toml:"-"`
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -33,26 +33,27 @@ 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"` |
|
||||
| `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 |
|
||||
| `foreground` | `string` | [color][colors] |
|
||||
| `foreground_templates` | `[]Template` | [color templates][color-templates] |
|
||||
| `background` | `string` | [color][colors] |
|
||||
| `background_templates` | `[]Template` | [color templates][color-templates] |
|
||||
| `template` | `string` | a go [text/template][go-text-template] [template][templates] to render the prompt |
|
||||
| `templates` | `[]Template` | in some cases having a single [template][templates] string is a bit cumbersome. Templates allows you to span the segment's [template][templates] string multiple lines where every [template][templates] is evaluated and depending on what you aim to achieve, there are two possible outcomes based on `templates_logic` |
|
||||
| `templates_logic` | `string` | <ul><li>`first_match`: return the first non-whitespace string and skip everything else</li><li>`join`:evaluate all templates and join all non-whitespace strings (**default**)</li></ul> |
|
||||
| `properties` | `[]Property` | see [Properties][properties] below |
|
||||
| `interactive` | `boolean` | when is true, the segment text is not escaped to allow the use of interactive prompt escape sequences - defaults to `false` |
|
||||
| `alias` | `string` | for use with [cross segment template properties][cstp] |
|
||||
| `min_width` | `int` | if the terminal width is smaller than this value, the segment will be hidden. For your terminal width, see `oh-my-posh get width`. Defaults to `0` (disable) |
|
||||
| `max_width` | `int` | if the terminal width exceeds this value, the segment will be hidden. For your terminal width, see `oh-my-posh get width`. Defaults to `0` (disable) |
|
||||
| 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 |
|
||||
| `foreground` | `string` | [color][colors] |
|
||||
| `foreground_templates` | `[]Template` | [color templates][color-templates] |
|
||||
| `background` | `string` | [color][colors] |
|
||||
| `background_templates` | `[]Template` | [color templates][color-templates] |
|
||||
| `template` | `string` | a go [text/template][go-text-template] [template][templates] to render the prompt |
|
||||
| `templates` | `[]Template` | in some cases having a single [template][templates] string is a bit cumbersome. Templates allows you to span the segment's [template][templates] string multiple lines where every [template][templates] is evaluated and depending on what you aim to achieve, there are two possible outcomes based on `templates_logic` |
|
||||
| `templates_logic` | `string` | <ul><li>`first_match`: return the first non-whitespace string and skip everything else</li><li>`join`:evaluate all templates and join all non-whitespace strings (**default**)</li></ul> |
|
||||
| `properties` | `[]Property` | see [Properties][properties] below |
|
||||
| `interactive` | `boolean` | when is true, the segment text is not escaped to allow the use of interactive prompt escape sequences - defaults to `false` |
|
||||
| `alias` | `string` | for use with [cross segment template properties][cstp] |
|
||||
| `min_width` | `int` | if the terminal width is smaller than this value, the segment will be hidden. For your terminal width, see `oh-my-posh get width`. Defaults to `0` (disable) |
|
||||
| `max_width` | `int` | if the terminal width exceeds this value, the segment will be hidden. For your terminal width, see `oh-my-posh get width`. Defaults to `0` (disable) |
|
||||
|
||||
## Style
|
||||
|
||||
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue