mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
parent
866ace7d46
commit
6ee743793a
|
@ -45,6 +45,9 @@ type Block struct {
|
||||||
Filler string `json:"filler,omitempty" toml:"filler,omitempty"`
|
Filler string `json:"filler,omitempty" toml:"filler,omitempty"`
|
||||||
Overflow Overflow `json:"overflow,omitempty" toml:"overflow,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
|
// Deprecated: keep the logic for legacy purposes
|
||||||
HorizontalOffset int `json:"horizontal_offset,omitempty" toml:"horizontal_offset,omitempty"`
|
HorizontalOffset int `json:"horizontal_offset,omitempty" toml:"horizontal_offset,omitempty"`
|
||||||
VerticalOffset int `json:"vertical_offset,omitempty" toml:"vertical_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) {
|
func (b *Block) RenderSegments() (string, int) {
|
||||||
for _, segment := range b.Segments {
|
b.filterSegments()
|
||||||
if !segment.Enabled && segment.style() != Accordion {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
|
for i, segment := range b.Segments {
|
||||||
if colors, newCycle := cycle.Loop(); colors != nil {
|
if colors, newCycle := cycle.Loop(); colors != nil {
|
||||||
cycle = &newCycle
|
cycle = &newCycle
|
||||||
segment.colors = colors
|
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.setActiveSegment(segment)
|
||||||
b.renderActiveSegment()
|
b.renderActiveSegment()
|
||||||
}
|
}
|
||||||
|
@ -150,6 +159,20 @@ func (b *Block) RenderSegments() (string, int) {
|
||||||
return b.writer.String()
|
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() {
|
func (b *Block) renderActiveSegment() {
|
||||||
b.writeSeparator(false)
|
b.writeSeparator(false)
|
||||||
switch b.activeSegment.style() {
|
switch b.activeSegment.style() {
|
||||||
|
|
|
@ -262,6 +262,18 @@
|
||||||
"description": "https://ohmyposh.dev/docs/configuration/block#newline",
|
"description": "https://ohmyposh.dev/docs/configuration/block#newline",
|
||||||
"default": false
|
"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": {
|
"segments": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"title": "Segments list, prompt elements to display based on context",
|
"title": "Segments list, prompt elements to display based on context",
|
||||||
|
|
|
@ -6,30 +6,34 @@ sidebar_label: Block
|
||||||
|
|
||||||
Let's take a closer look at what defines a 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={{
|
<Config
|
||||||
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
|
data={{
|
||||||
"blocks": [
|
$schema:
|
||||||
{
|
"https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
|
||||||
"type": "prompt",
|
blocks: [
|
||||||
"alignment": "left",
|
{
|
||||||
"segments": [
|
type: "prompt",
|
||||||
]
|
alignment: "left",
|
||||||
}
|
segments: [],
|
||||||
]
|
},
|
||||||
}}/>
|
],
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
## Properties
|
## Properties
|
||||||
|
|
||||||
| Name | Type |
|
| Name | Type |
|
||||||
| ----------- | --------- |
|
| ------------------ | --------- |
|
||||||
| `type` | `string` |
|
| `type` | `string` |
|
||||||
| `newline` | `boolean` |
|
| `newline` | `boolean` |
|
||||||
| `alignment` | `string` |
|
| `alignment` | `string` |
|
||||||
| `filler` | `string` |
|
| `filler` | `string` |
|
||||||
| `overflow` | `string` |
|
| `overflow` | `string` |
|
||||||
| `segments` | `array` |
|
| `leading_diamond` | `string` |
|
||||||
|
| `trailing_diamond` | `string` |
|
||||||
|
| `segments` | `array` |
|
||||||
|
|
||||||
### Type
|
### 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
|
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.
|
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
|
### Segments
|
||||||
|
|
||||||
Array of one or more [segments][segment].
|
Array of one or more [segments][segment].
|
||||||
|
|
Loading…
Reference in a new issue