mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-26 19:39:39 -08:00
parent
866ace7d46
commit
6ee743793a
|
@ -45,6 +45,9 @@ type Block struct {
|
|||
Filler string `json:"filler,omitempty" toml:"filler,omitempty"`
|
||||
Overflow Overflow `json:"overflow,omitempty" toml:"overflow,omitempty"`
|
||||
|
||||
LeadingDiamond string `json:"leading_diamond,omitempty" toml:"leading_diamond,omitempty"`
|
||||
TrailingDiamond string `json:"trailing_diamond,omitempty" toml:"trailing_diamond,omitempty"`
|
||||
|
||||
// Deprecated: keep the logic for legacy purposes
|
||||
HorizontalOffset int `json:"horizontal_offset,omitempty" toml:"horizontal_offset,omitempty"`
|
||||
VerticalOffset int `json:"vertical_offset,omitempty" toml:"vertical_offset,omitempty"`
|
||||
|
@ -131,16 +134,22 @@ func (b *Block) setSegmentsText() {
|
|||
}
|
||||
|
||||
func (b *Block) RenderSegments() (string, int) {
|
||||
for _, segment := range b.Segments {
|
||||
if !segment.Enabled && segment.style() != Accordion {
|
||||
continue
|
||||
}
|
||||
b.filterSegments()
|
||||
|
||||
for i, segment := range b.Segments {
|
||||
if colors, newCycle := cycle.Loop(); colors != nil {
|
||||
cycle = &newCycle
|
||||
segment.colors = colors
|
||||
}
|
||||
|
||||
if i == 0 && len(b.LeadingDiamond) > 0 {
|
||||
segment.LeadingDiamond = b.LeadingDiamond
|
||||
}
|
||||
|
||||
if i == len(b.Segments)-1 && len(b.TrailingDiamond) > 0 {
|
||||
segment.TrailingDiamond = b.TrailingDiamond
|
||||
}
|
||||
|
||||
b.setActiveSegment(segment)
|
||||
b.renderActiveSegment()
|
||||
}
|
||||
|
@ -150,6 +159,20 @@ func (b *Block) RenderSegments() (string, int) {
|
|||
return b.writer.String()
|
||||
}
|
||||
|
||||
func (b *Block) filterSegments() {
|
||||
segments := make([]*Segment, 0)
|
||||
|
||||
for _, segment := range b.Segments {
|
||||
if !segment.Enabled && segment.style() != Accordion {
|
||||
continue
|
||||
}
|
||||
|
||||
segments = append(segments, segment)
|
||||
}
|
||||
|
||||
b.Segments = segments
|
||||
}
|
||||
|
||||
func (b *Block) renderActiveSegment() {
|
||||
b.writeSeparator(false)
|
||||
switch b.activeSegment.style() {
|
||||
|
|
|
@ -262,6 +262,18 @@
|
|||
"description": "https://ohmyposh.dev/docs/configuration/block#newline",
|
||||
"default": false
|
||||
},
|
||||
"leading_diamond": {
|
||||
"type": "string",
|
||||
"title": "Leading diamond",
|
||||
"description": "https://ohmyposh.dev/docs/configuration/block#leading-diamond",
|
||||
"default": ""
|
||||
},
|
||||
"trailing_diamond": {
|
||||
"type": "string",
|
||||
"title": "Trailing diamond",
|
||||
"description": "https://ohmyposh.dev/docs/configuration/block#trailing-diamond",
|
||||
"default": ""
|
||||
},
|
||||
"segments": {
|
||||
"type": "array",
|
||||
"title": "Segments list, prompt elements to display based on context",
|
||||
|
|
|
@ -6,29 +6,33 @@ sidebar_label: Block
|
|||
|
||||
Let's take a closer look at what defines a block.
|
||||
|
||||
import Config from '@site/src/components/Config.js';
|
||||
import Config from "@site/src/components/Config.js";
|
||||
|
||||
<Config data={{
|
||||
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
|
||||
"blocks": [
|
||||
<Config
|
||||
data={{
|
||||
$schema:
|
||||
"https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
|
||||
blocks: [
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"segments": [
|
||||
]
|
||||
}
|
||||
]
|
||||
}}/>
|
||||
type: "prompt",
|
||||
alignment: "left",
|
||||
segments: [],
|
||||
},
|
||||
],
|
||||
}}
|
||||
/>
|
||||
|
||||
## Properties
|
||||
|
||||
| Name | Type |
|
||||
| ----------- | --------- |
|
||||
| ------------------ | --------- |
|
||||
| `type` | `string` |
|
||||
| `newline` | `boolean` |
|
||||
| `alignment` | `string` |
|
||||
| `filler` | `string` |
|
||||
| `overflow` | `string` |
|
||||
| `leading_diamond` | `string` |
|
||||
| `trailing_diamond` | `string` |
|
||||
| `segments` | `array` |
|
||||
|
||||
### Type
|
||||
|
@ -71,6 +75,16 @@ to be repeated to this property. Add this property to the _right_ aligned block.
|
|||
When the right aligned block is so long it will overflow the left aligned block, the engine will either
|
||||
break the block or hide it based on the setting. By default it is printed as is on the same line.
|
||||
|
||||
### Leading Diamond
|
||||
|
||||
The character to use as a leading diamond for the first segment in case you always want to start the block
|
||||
with the same leading diamond, regardless of which segment is enabled or not.
|
||||
|
||||
### Trailing Diamond
|
||||
|
||||
The character to use as a trailing diamond for the last segment in case you always want to end the block
|
||||
with the same trailing diamond, regardless of which segment is enabled or not.
|
||||
|
||||
### Segments
|
||||
|
||||
Array of one or more [segments][segment].
|
||||
|
|
Loading…
Reference in a new issue