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`
|
||||
- newline: `boolean`
|
||||
- alignment: `left` | `right`
|
||||
- vertical_offset: `int`
|
||||
- horizontal_offset: `int`
|
||||
- filler: `string`
|
||||
- segments: `array` of one or more `segments`
|
||||
|
||||
### 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.
|
||||
|
||||
### 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`
|
||||
moves it up one line.
|
||||
When you want to join a right and left aligned block with a repeated set of characters, add the character
|
||||
to be repeated to this property. Add this property to the _left_ aligned block.
|
||||
|
||||
### Horizontal offset
|
||||
|
||||
Moves the segment to the left or the right to have it exactly where you want it to be. Works like `vertical_offset`
|
||||
but on a horizontal level where a negative number moves the block left and a positive number right.
|
||||
```json
|
||||
"alignment": "left",
|
||||
"filler": "."
|
||||
```
|
||||
|
||||
### Segments
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ type Block struct {
|
|||
VerticalOffset int `json:"vertical_offset,omitempty"`
|
||||
Segments []*Segment `json:"segments,omitempty"`
|
||||
Newline bool `json:"newline,omitempty"`
|
||||
Filler string `json:"filler,omitempty"`
|
||||
|
||||
env environment.Environment
|
||||
writer color.Writer
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"oh-my-posh/template"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
type Engine struct {
|
||||
|
@ -92,6 +93,20 @@ func (e *Engine) renderBlock(block *Block) {
|
|||
if !block.enabled() {
|
||||
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 {
|
||||
e.newline()
|
||||
}
|
||||
|
@ -107,10 +122,13 @@ func (e *Engine) renderBlock(block *Block) {
|
|||
}
|
||||
switch block.Alignment {
|
||||
case Right:
|
||||
e.writeANSI(e.Ansi.CarriageForward())
|
||||
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.currentLineLength = 0
|
||||
e.write(text)
|
||||
case Left:
|
||||
text, length := block.renderSegments()
|
||||
|
|
|
@ -76,7 +76,7 @@
|
|||
{
|
||||
"background": "#303030",
|
||||
"foreground": "#3C873A",
|
||||
"leading_diamond": " \ue0b6",
|
||||
"leading_diamond": "\ue0b6",
|
||||
"properties": {
|
||||
"fetch_package_manager": true,
|
||||
"npm_icon": " <#cc3a3a>\ue5fa</> ",
|
||||
|
@ -84,62 +84,62 @@
|
|||
"yarn_icon": " <#348cba>\uf61a</>"
|
||||
},
|
||||
"style": "diamond",
|
||||
"trailing_diamond": "\ue0b4",
|
||||
"trailing_diamond": "\ue0b4 ",
|
||||
"type": "node"
|
||||
},
|
||||
{
|
||||
"background": "#306998",
|
||||
"foreground": "#FFE873",
|
||||
"leading_diamond": " \ue0b6",
|
||||
"leading_diamond": "\ue0b6",
|
||||
"properties": {
|
||||
"template": "\ue235 {{ if .Error }}{{ .Error }}{{ else }}{{ if .Venv }}{{ .Venv }} {{ end }}{{ .Full }}{{ end }}"
|
||||
},
|
||||
"style": "diamond",
|
||||
"trailing_diamond": "\ue0b4",
|
||||
"trailing_diamond": "\ue0b4 ",
|
||||
"type": "python"
|
||||
},
|
||||
{
|
||||
"background": "#0e8ac8",
|
||||
"foreground": "#ec2729",
|
||||
"leading_diamond": " \ue0b6",
|
||||
"leading_diamond": "\ue0b6",
|
||||
"properties": {
|
||||
"template": "\ue738 {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}"
|
||||
},
|
||||
"style": "diamond",
|
||||
"trailing_diamond": "\ue0b4",
|
||||
"trailing_diamond": "\ue0b4 ",
|
||||
"type": "java"
|
||||
},
|
||||
{
|
||||
"background": "#0e0e0e",
|
||||
"foreground": "#0d6da8",
|
||||
"leading_diamond": " \ue0b6",
|
||||
"leading_diamond": "\ue0b6",
|
||||
"properties": {
|
||||
"template": "\ue77f {{ if .Unsupported }}\uf071{{ else }}{{ .Full }}{{ end }}"
|
||||
},
|
||||
"style": "diamond",
|
||||
"trailing_diamond": "\ue0b4",
|
||||
"trailing_diamond": "\ue0b4 ",
|
||||
"type": "dotnet"
|
||||
},
|
||||
{
|
||||
"background": "#ffffff",
|
||||
"foreground": "#06aad5",
|
||||
"leading_diamond": " \ue0b6",
|
||||
"leading_diamond": "\ue0b6",
|
||||
"properties": {
|
||||
"template": "\ufcd1 {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}"
|
||||
},
|
||||
"style": "diamond",
|
||||
"trailing_diamond": "\ue0b4",
|
||||
"trailing_diamond": "\ue0b4 ",
|
||||
"type": "go"
|
||||
},
|
||||
{
|
||||
"background": "#f3f0ec",
|
||||
"foreground": "#925837",
|
||||
"leading_diamond": " \ue0b6",
|
||||
"leading_diamond": "\ue0b6",
|
||||
"properties": {
|
||||
"template": "\ue7a8 {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}"
|
||||
},
|
||||
"style": "diamond",
|
||||
"trailing_diamond": "\ue0b4",
|
||||
"trailing_diamond": "\ue0b4 ",
|
||||
"type": "rust"
|
||||
},
|
||||
{
|
||||
|
@ -150,7 +150,7 @@
|
|||
"template": "\ue798 {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}"
|
||||
},
|
||||
"style": "diamond",
|
||||
"trailing_diamond": "\ue0b4",
|
||||
"trailing_diamond": "\ue0b4 ",
|
||||
"type": "dart"
|
||||
},
|
||||
{
|
||||
|
@ -161,7 +161,7 @@
|
|||
"template": "\ue753 {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}"
|
||||
},
|
||||
"style": "diamond",
|
||||
"trailing_diamond": "\ue0b4",
|
||||
"trailing_diamond": "\ue0b4 ",
|
||||
"type": "angular"
|
||||
},
|
||||
{
|
||||
|
@ -172,46 +172,46 @@
|
|||
"template": "<#ca3c34>\ue624</> {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}"
|
||||
},
|
||||
"style": "diamond",
|
||||
"trailing_diamond": "\ue0b4",
|
||||
"trailing_diamond": "\ue0b4 ",
|
||||
"type": "julia"
|
||||
},
|
||||
{
|
||||
"background": "#ffffff",
|
||||
"foreground": "#9c1006",
|
||||
"leading_diamond": " \ue0b6",
|
||||
"leading_diamond": "\ue0b6",
|
||||
"properties": {
|
||||
"template": "\ue791 {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}"
|
||||
},
|
||||
"style": "diamond",
|
||||
"trailing_diamond": "\ue0b4",
|
||||
"trailing_diamond": "\ue0b4 ",
|
||||
"type": "ruby"
|
||||
},
|
||||
{
|
||||
"background": "#ffffff",
|
||||
"foreground": "#5398c2",
|
||||
"leading_diamond": " \ue0b6",
|
||||
"leading_diamond": "\ue0b6",
|
||||
"properties": {
|
||||
"template": "\uf104<#f5bf45>\uf0e7</>\uf105 {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}"
|
||||
},
|
||||
"style": "diamond",
|
||||
"trailing_diamond": "\ue0b4",
|
||||
"trailing_diamond": "\ue0b4 ",
|
||||
"type": "azfunc"
|
||||
},
|
||||
{
|
||||
"background": "#565656",
|
||||
"foreground": "#faa029",
|
||||
"leading_diamond": " \ue0b6",
|
||||
"leading_diamond": "\ue0b6",
|
||||
"properties": {
|
||||
"template": "\ue7ad {{.Profile}}{{if .Region}}@{{.Region}}{{end}}"
|
||||
},
|
||||
"style": "diamond",
|
||||
"trailing_diamond": "\ue0b4",
|
||||
"trailing_diamond": "\ue0b4 ",
|
||||
"type": "aws"
|
||||
},
|
||||
{
|
||||
"background": "#316ce4",
|
||||
"foreground": "#ffffff",
|
||||
"leading_diamond": " \ue0b6",
|
||||
"leading_diamond": "\ue0b6",
|
||||
"properties": {
|
||||
"template": "\ufd31 {{.Context}}{{if .Namespace}} :: {{.Namespace}}{{end}}"
|
||||
},
|
||||
|
@ -222,7 +222,7 @@
|
|||
{
|
||||
"background": "#b2bec3",
|
||||
"foreground": "#222222",
|
||||
"leading_diamond": " \ue0b6",
|
||||
"leading_diamond": "\ue0b6",
|
||||
"properties": {
|
||||
"linux": "\ue27f",
|
||||
"macos": "\ue27f",
|
||||
|
|
Loading…
Reference in a new issue