mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-02 05:41:10 -08:00
feat: filler between blocks
This commit is contained in:
parent
04e6579a8e
commit
aba4093aba
|
@ -25,8 +25,7 @@ Let's take a closer look at what defines a block.
|
||||||
- type: `prompt` | `rprompt`
|
- type: `prompt` | `rprompt`
|
||||||
- newline: `boolean`
|
- newline: `boolean`
|
||||||
- alignment: `left` | `right`
|
- alignment: `left` | `right`
|
||||||
- vertical_offset: `int`
|
- filler: `string`
|
||||||
- horizontal_offset: `int`
|
|
||||||
- segments: `array` of one or more `segments`
|
- segments: `array` of one or more `segments`
|
||||||
|
|
||||||
### Type
|
### Type
|
||||||
|
@ -45,15 +44,15 @@ Start the block on a new line - defaults to `false`.
|
||||||
|
|
||||||
Tell the engine if the block should be left or right-aligned.
|
Tell the engine if the block should be left or right-aligned.
|
||||||
|
|
||||||
### Vertical offset
|
### Filler
|
||||||
|
|
||||||
Move the block up or down x lines. For example, `vertical_offset: 1` moves the prompt down one line, `vertical_offset: -1`
|
When you want to join a right and left aligned block with a repeated set of characters, add the character
|
||||||
moves it up one line.
|
to be repeated to this property. Add this property to the _left_ aligned block.
|
||||||
|
|
||||||
### Horizontal offset
|
```json
|
||||||
|
"alignment": "left",
|
||||||
Moves the segment to the left or the right to have it exactly where you want it to be. Works like `vertical_offset`
|
"filler": "."
|
||||||
but on a horizontal level where a negative number moves the block left and a positive number right.
|
```
|
||||||
|
|
||||||
### Segments
|
### Segments
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ type Block struct {
|
||||||
VerticalOffset int `json:"vertical_offset,omitempty"`
|
VerticalOffset int `json:"vertical_offset,omitempty"`
|
||||||
Segments []*Segment `json:"segments,omitempty"`
|
Segments []*Segment `json:"segments,omitempty"`
|
||||||
Newline bool `json:"newline,omitempty"`
|
Newline bool `json:"newline,omitempty"`
|
||||||
|
Filler string `json:"filler,omitempty"`
|
||||||
|
|
||||||
env environment.Environment
|
env environment.Environment
|
||||||
writer color.Writer
|
writer color.Writer
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"oh-my-posh/template"
|
"oh-my-posh/template"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Engine struct {
|
type Engine struct {
|
||||||
|
@ -92,6 +93,20 @@ func (e *Engine) renderBlock(block *Block) {
|
||||||
if !block.enabled() {
|
if !block.enabled() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
shouldFill := func(blockLength int) (string, bool) {
|
||||||
|
if len(block.Filler) == 0 {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
if terminalWidth, err := e.Env.TerminalWidth(); err == nil && terminalWidth > 0 {
|
||||||
|
padLength := terminalWidth - e.currentLineLength - blockLength
|
||||||
|
var filler string
|
||||||
|
for utf8.RuneCountInString(filler) < padLength {
|
||||||
|
filler += block.Filler
|
||||||
|
}
|
||||||
|
return filler, true
|
||||||
|
}
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
if block.Newline {
|
if block.Newline {
|
||||||
e.newline()
|
e.newline()
|
||||||
}
|
}
|
||||||
|
@ -107,10 +122,13 @@ func (e *Engine) renderBlock(block *Block) {
|
||||||
}
|
}
|
||||||
switch block.Alignment {
|
switch block.Alignment {
|
||||||
case Right:
|
case Right:
|
||||||
e.writeANSI(e.Ansi.CarriageForward())
|
|
||||||
text, length := block.renderSegments()
|
text, length := block.renderSegments()
|
||||||
e.currentLineLength += length
|
if padText, OK := shouldFill(length); OK {
|
||||||
|
e.write(padText)
|
||||||
|
}
|
||||||
|
e.writeANSI(e.Ansi.CarriageForward())
|
||||||
e.writeANSI(e.Ansi.GetCursorForRightWrite(length, block.HorizontalOffset))
|
e.writeANSI(e.Ansi.GetCursorForRightWrite(length, block.HorizontalOffset))
|
||||||
|
e.currentLineLength = 0
|
||||||
e.write(text)
|
e.write(text)
|
||||||
case Left:
|
case Left:
|
||||||
text, length := block.renderSegments()
|
text, length := block.renderSegments()
|
||||||
|
|
|
@ -76,7 +76,7 @@
|
||||||
{
|
{
|
||||||
"background": "#303030",
|
"background": "#303030",
|
||||||
"foreground": "#3C873A",
|
"foreground": "#3C873A",
|
||||||
"leading_diamond": " \ue0b6",
|
"leading_diamond": "\ue0b6",
|
||||||
"properties": {
|
"properties": {
|
||||||
"fetch_package_manager": true,
|
"fetch_package_manager": true,
|
||||||
"npm_icon": " <#cc3a3a>\ue5fa</> ",
|
"npm_icon": " <#cc3a3a>\ue5fa</> ",
|
||||||
|
@ -84,62 +84,62 @@
|
||||||
"yarn_icon": " <#348cba>\uf61a</>"
|
"yarn_icon": " <#348cba>\uf61a</>"
|
||||||
},
|
},
|
||||||
"style": "diamond",
|
"style": "diamond",
|
||||||
"trailing_diamond": "\ue0b4",
|
"trailing_diamond": "\ue0b4 ",
|
||||||
"type": "node"
|
"type": "node"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"background": "#306998",
|
"background": "#306998",
|
||||||
"foreground": "#FFE873",
|
"foreground": "#FFE873",
|
||||||
"leading_diamond": " \ue0b6",
|
"leading_diamond": "\ue0b6",
|
||||||
"properties": {
|
"properties": {
|
||||||
"template": "\ue235 {{ if .Error }}{{ .Error }}{{ else }}{{ if .Venv }}{{ .Venv }} {{ end }}{{ .Full }}{{ end }}"
|
"template": "\ue235 {{ if .Error }}{{ .Error }}{{ else }}{{ if .Venv }}{{ .Venv }} {{ end }}{{ .Full }}{{ end }}"
|
||||||
},
|
},
|
||||||
"style": "diamond",
|
"style": "diamond",
|
||||||
"trailing_diamond": "\ue0b4",
|
"trailing_diamond": "\ue0b4 ",
|
||||||
"type": "python"
|
"type": "python"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"background": "#0e8ac8",
|
"background": "#0e8ac8",
|
||||||
"foreground": "#ec2729",
|
"foreground": "#ec2729",
|
||||||
"leading_diamond": " \ue0b6",
|
"leading_diamond": "\ue0b6",
|
||||||
"properties": {
|
"properties": {
|
||||||
"template": "\ue738 {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}"
|
"template": "\ue738 {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}"
|
||||||
},
|
},
|
||||||
"style": "diamond",
|
"style": "diamond",
|
||||||
"trailing_diamond": "\ue0b4",
|
"trailing_diamond": "\ue0b4 ",
|
||||||
"type": "java"
|
"type": "java"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"background": "#0e0e0e",
|
"background": "#0e0e0e",
|
||||||
"foreground": "#0d6da8",
|
"foreground": "#0d6da8",
|
||||||
"leading_diamond": " \ue0b6",
|
"leading_diamond": "\ue0b6",
|
||||||
"properties": {
|
"properties": {
|
||||||
"template": "\ue77f {{ if .Unsupported }}\uf071{{ else }}{{ .Full }}{{ end }}"
|
"template": "\ue77f {{ if .Unsupported }}\uf071{{ else }}{{ .Full }}{{ end }}"
|
||||||
},
|
},
|
||||||
"style": "diamond",
|
"style": "diamond",
|
||||||
"trailing_diamond": "\ue0b4",
|
"trailing_diamond": "\ue0b4 ",
|
||||||
"type": "dotnet"
|
"type": "dotnet"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"background": "#ffffff",
|
"background": "#ffffff",
|
||||||
"foreground": "#06aad5",
|
"foreground": "#06aad5",
|
||||||
"leading_diamond": " \ue0b6",
|
"leading_diamond": "\ue0b6",
|
||||||
"properties": {
|
"properties": {
|
||||||
"template": "\ufcd1 {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}"
|
"template": "\ufcd1 {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}"
|
||||||
},
|
},
|
||||||
"style": "diamond",
|
"style": "diamond",
|
||||||
"trailing_diamond": "\ue0b4",
|
"trailing_diamond": "\ue0b4 ",
|
||||||
"type": "go"
|
"type": "go"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"background": "#f3f0ec",
|
"background": "#f3f0ec",
|
||||||
"foreground": "#925837",
|
"foreground": "#925837",
|
||||||
"leading_diamond": " \ue0b6",
|
"leading_diamond": "\ue0b6",
|
||||||
"properties": {
|
"properties": {
|
||||||
"template": "\ue7a8 {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}"
|
"template": "\ue7a8 {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}"
|
||||||
},
|
},
|
||||||
"style": "diamond",
|
"style": "diamond",
|
||||||
"trailing_diamond": "\ue0b4",
|
"trailing_diamond": "\ue0b4 ",
|
||||||
"type": "rust"
|
"type": "rust"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -150,7 +150,7 @@
|
||||||
"template": "\ue798 {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}"
|
"template": "\ue798 {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}"
|
||||||
},
|
},
|
||||||
"style": "diamond",
|
"style": "diamond",
|
||||||
"trailing_diamond": "\ue0b4",
|
"trailing_diamond": "\ue0b4 ",
|
||||||
"type": "dart"
|
"type": "dart"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -161,7 +161,7 @@
|
||||||
"template": "\ue753 {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}"
|
"template": "\ue753 {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}"
|
||||||
},
|
},
|
||||||
"style": "diamond",
|
"style": "diamond",
|
||||||
"trailing_diamond": "\ue0b4",
|
"trailing_diamond": "\ue0b4 ",
|
||||||
"type": "angular"
|
"type": "angular"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -172,46 +172,46 @@
|
||||||
"template": "<#ca3c34>\ue624</> {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}"
|
"template": "<#ca3c34>\ue624</> {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}"
|
||||||
},
|
},
|
||||||
"style": "diamond",
|
"style": "diamond",
|
||||||
"trailing_diamond": "\ue0b4",
|
"trailing_diamond": "\ue0b4 ",
|
||||||
"type": "julia"
|
"type": "julia"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"background": "#ffffff",
|
"background": "#ffffff",
|
||||||
"foreground": "#9c1006",
|
"foreground": "#9c1006",
|
||||||
"leading_diamond": " \ue0b6",
|
"leading_diamond": "\ue0b6",
|
||||||
"properties": {
|
"properties": {
|
||||||
"template": "\ue791 {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}"
|
"template": "\ue791 {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}"
|
||||||
},
|
},
|
||||||
"style": "diamond",
|
"style": "diamond",
|
||||||
"trailing_diamond": "\ue0b4",
|
"trailing_diamond": "\ue0b4 ",
|
||||||
"type": "ruby"
|
"type": "ruby"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"background": "#ffffff",
|
"background": "#ffffff",
|
||||||
"foreground": "#5398c2",
|
"foreground": "#5398c2",
|
||||||
"leading_diamond": " \ue0b6",
|
"leading_diamond": "\ue0b6",
|
||||||
"properties": {
|
"properties": {
|
||||||
"template": "\uf104<#f5bf45>\uf0e7</>\uf105 {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}"
|
"template": "\uf104<#f5bf45>\uf0e7</>\uf105 {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}"
|
||||||
},
|
},
|
||||||
"style": "diamond",
|
"style": "diamond",
|
||||||
"trailing_diamond": "\ue0b4",
|
"trailing_diamond": "\ue0b4 ",
|
||||||
"type": "azfunc"
|
"type": "azfunc"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"background": "#565656",
|
"background": "#565656",
|
||||||
"foreground": "#faa029",
|
"foreground": "#faa029",
|
||||||
"leading_diamond": " \ue0b6",
|
"leading_diamond": "\ue0b6",
|
||||||
"properties": {
|
"properties": {
|
||||||
"template": "\ue7ad {{.Profile}}{{if .Region}}@{{.Region}}{{end}}"
|
"template": "\ue7ad {{.Profile}}{{if .Region}}@{{.Region}}{{end}}"
|
||||||
},
|
},
|
||||||
"style": "diamond",
|
"style": "diamond",
|
||||||
"trailing_diamond": "\ue0b4",
|
"trailing_diamond": "\ue0b4 ",
|
||||||
"type": "aws"
|
"type": "aws"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"background": "#316ce4",
|
"background": "#316ce4",
|
||||||
"foreground": "#ffffff",
|
"foreground": "#ffffff",
|
||||||
"leading_diamond": " \ue0b6",
|
"leading_diamond": "\ue0b6",
|
||||||
"properties": {
|
"properties": {
|
||||||
"template": "\ufd31 {{.Context}}{{if .Namespace}} :: {{.Namespace}}{{end}}"
|
"template": "\ufd31 {{.Context}}{{if .Namespace}} :: {{.Namespace}}{{end}}"
|
||||||
},
|
},
|
||||||
|
@ -222,7 +222,7 @@
|
||||||
{
|
{
|
||||||
"background": "#b2bec3",
|
"background": "#b2bec3",
|
||||||
"foreground": "#222222",
|
"foreground": "#222222",
|
||||||
"leading_diamond": " \ue0b6",
|
"leading_diamond": "\ue0b6",
|
||||||
"properties": {
|
"properties": {
|
||||||
"linux": "\ue27f",
|
"linux": "\ue27f",
|
||||||
"macos": "\ue27f",
|
"macos": "\ue27f",
|
||||||
|
|
Loading…
Reference in a new issue