mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-09 20:44:03 -08:00
feat: add accordion segment style
This commit is contained in:
parent
23c2c383fe
commit
5e02063323
|
@ -33,7 +33,7 @@ understand how to configure a segment.
|
|||
```
|
||||
|
||||
- type: `string` any of the included [segments][segments]
|
||||
- style: `powerline` | `plain` | `diamond`
|
||||
- style: `powerline` | `plain` | `diamond` | `accordion`
|
||||
- powerline_symbol: `string`
|
||||
- invert_powerline: `boolean`
|
||||
- leading_diamond: `string`
|
||||
|
@ -72,6 +72,11 @@ While Powerline works great with a single symbol, sometimes you want a segment t
|
|||
Just like a diamond: `< my segment text >`. The difference between this and plain is that the diamond symbols take the
|
||||
segment background as their foreground color.
|
||||
|
||||
### Accordion
|
||||
|
||||
Same as Powerline except that it will display even when disabled, but without text. That way it seems
|
||||
as if the segment is not expanded, just like an accordion.
|
||||
|
||||
## Powerline symbol
|
||||
|
||||
Text character to use when `"style": "powerline"`.
|
||||
|
|
|
@ -93,7 +93,7 @@ func (b *Block) renderSegmentsText() {
|
|||
func (b *Block) renderSegments() (string, int) {
|
||||
defer b.writer.Reset()
|
||||
for _, segment := range b.Segments {
|
||||
if !segment.enabled {
|
||||
if !segment.enabled && segment.Style != Accordion {
|
||||
continue
|
||||
}
|
||||
b.renderSegment(segment)
|
||||
|
@ -113,6 +113,10 @@ func (b *Block) renderSegment(segment *Segment) {
|
|||
b.writer.Write(color.Transparent, color.Background, b.activeSegment.LeadingDiamond)
|
||||
b.writer.Write(color.Background, color.Foreground, segment.text)
|
||||
b.writer.Write(color.Transparent, color.Background, b.activeSegment.TrailingDiamond)
|
||||
case Accordion:
|
||||
if segment.enabled {
|
||||
b.writer.Write(color.Background, color.Foreground, segment.text)
|
||||
}
|
||||
}
|
||||
b.previousActiveSegment = b.activeSegment
|
||||
b.writer.SetParentColors(b.previousActiveSegment.background(), b.previousActiveSegment.foreground())
|
||||
|
@ -121,9 +125,9 @@ func (b *Block) renderSegment(segment *Segment) {
|
|||
func (b *Block) writePowerline(final bool) {
|
||||
resolvePowerlineSymbol := func() string {
|
||||
var symbol string
|
||||
if b.activeSegment.Style == Powerline {
|
||||
if b.activeSegment.isPowerline() {
|
||||
symbol = b.activeSegment.PowerlineSymbol
|
||||
} else if b.previousActiveSegment != nil && b.previousActiveSegment.Style == Powerline {
|
||||
} else if b.previousActiveSegment != nil && b.previousActiveSegment.isPowerline() {
|
||||
symbol = b.previousActiveSegment.PowerlineSymbol
|
||||
}
|
||||
return symbol
|
||||
|
@ -133,7 +137,7 @@ func (b *Block) writePowerline(final bool) {
|
|||
return
|
||||
}
|
||||
bgColor := color.Background
|
||||
if final || b.activeSegment.Style != Powerline {
|
||||
if final || !b.activeSegment.isPowerline() {
|
||||
bgColor = color.Transparent
|
||||
}
|
||||
if b.activeSegment.Style == Diamond && len(b.activeSegment.LeadingDiamond) == 0 {
|
||||
|
@ -156,7 +160,7 @@ func (b *Block) getPowerlineColor() string {
|
|||
if b.activeSegment.Style == Diamond && len(b.activeSegment.LeadingDiamond) == 0 {
|
||||
return b.previousActiveSegment.background()
|
||||
}
|
||||
if b.previousActiveSegment.Style != Powerline {
|
||||
if !b.previousActiveSegment.isPowerline() {
|
||||
return color.Transparent
|
||||
}
|
||||
return b.previousActiveSegment.background()
|
||||
|
|
|
@ -60,6 +60,15 @@ type SegmentStyle string
|
|||
type SegmentType string
|
||||
|
||||
const (
|
||||
// Powerline writes it Powerline style
|
||||
Powerline SegmentStyle = "powerline"
|
||||
// Accordion writes it Powerline style but collapses the segment when disabled instead of hiding
|
||||
Accordion SegmentStyle = "accordion"
|
||||
// Plain writes it without ornaments
|
||||
Plain SegmentStyle = "plain"
|
||||
// Diamond writes the prompt shaped with a leading and trailing symbol
|
||||
Diamond SegmentStyle = "diamond"
|
||||
|
||||
// SESSION represents the user info segment
|
||||
SESSION SegmentType = "session"
|
||||
// PATH represents the current path segment
|
||||
|
@ -102,12 +111,6 @@ const (
|
|||
GOLANG SegmentType = "go"
|
||||
// JULIA writes which julia version is currently active
|
||||
JULIA SegmentType = "julia"
|
||||
// Powerline writes it Powerline style
|
||||
Powerline SegmentStyle = "powerline"
|
||||
// Plain writes it without ornaments
|
||||
Plain SegmentStyle = "plain"
|
||||
// Diamond writes the prompt shaped with a leading and trailing symbol
|
||||
Diamond SegmentStyle = "diamond"
|
||||
// YTM writes YouTube Music information and status
|
||||
YTM SegmentType = "ytm"
|
||||
// EXECUTIONTIME writes the execution time of the last run command
|
||||
|
@ -183,6 +186,10 @@ func (segment *Segment) shouldIncludeFolder() bool {
|
|||
return cwdIncluded && !cwdExcluded
|
||||
}
|
||||
|
||||
func (segment *Segment) isPowerline() bool {
|
||||
return segment.Style == Powerline || segment.Style == Accordion
|
||||
}
|
||||
|
||||
func (segment *Segment) cwdIncluded() bool {
|
||||
value, ok := segment.Properties[properties.IncludeFolders]
|
||||
if !ok {
|
||||
|
|
|
@ -207,7 +207,7 @@
|
|||
"type": "string",
|
||||
"title": "Segment Style",
|
||||
"description": "https://ohmyposh.dev/docs/config-segment#style",
|
||||
"enum": ["powerline", "plain", "diamond"]
|
||||
"enum": ["powerline", "plain", "diamond", "accordion"]
|
||||
},
|
||||
"foreground": { "$ref": "#/definitions/color" },
|
||||
"foreground_templates": { "$ref": "#/definitions/color_templates" },
|
||||
|
|
Loading…
Reference in a new issue