mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-27 11:59:40 -08:00
feat: colorise filler
This commit is contained in:
parent
d3d370309f
commit
a0d4fc6cba
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
|
@ -10,7 +10,7 @@
|
|||
"args": [
|
||||
"--config=${workspaceRoot}/themes/jandedobbeleer.omp.json",
|
||||
"--shell=pwsh",
|
||||
"--pwd=/Users/jan/Projects/test"
|
||||
"--terminal-width=200",
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
@ -46,8 +46,9 @@ Tell the engine if the block should be left or right-aligned.
|
|||
|
||||
### Filler
|
||||
|
||||
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 _right_ aligned block.
|
||||
When you want to join a right and left aligned block with a repeated set of characters, add the character(s)
|
||||
to be repeated to this property. Add this property to the _right_ aligned block. This supports the use of
|
||||
[color overrides][color-overrides].
|
||||
|
||||
```json
|
||||
"alignment": "right",
|
||||
|
@ -57,3 +58,5 @@ to be repeated to this property. Add this property to the _right_ aligned block.
|
|||
### Segments
|
||||
|
||||
Array of one or more segments.
|
||||
|
||||
[color-overrides]: /docs/config-colors#color-overrides
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"oh-my-posh/template"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
type Engine struct {
|
||||
|
@ -81,6 +80,28 @@ func (e *Engine) newline() {
|
|||
e.currentLineLength = 0
|
||||
}
|
||||
|
||||
func (e *Engine) shouldFill(block *Block, length int) (string, bool) {
|
||||
if len(block.Filler) == 0 {
|
||||
return "", false
|
||||
}
|
||||
terminalWidth, err := e.Env.TerminalWidth()
|
||||
if err != nil && terminalWidth == 0 {
|
||||
return "", false
|
||||
}
|
||||
padLength := terminalWidth - e.currentLineLength - length
|
||||
if padLength <= 0 {
|
||||
return "", false
|
||||
}
|
||||
e.Writer.Write("", "", block.Filler)
|
||||
filler, lenFiller := e.Writer.String()
|
||||
e.Writer.Reset()
|
||||
if lenFiller == 0 {
|
||||
return "", false
|
||||
}
|
||||
repeat := padLength / lenFiller
|
||||
return strings.Repeat(filler, repeat), true
|
||||
}
|
||||
|
||||
func (e *Engine) renderBlock(block *Block) {
|
||||
// when in bash, for rprompt blocks we need to write plain
|
||||
// and wrap in escaped mode or the prompt will not render correctly
|
||||
|
@ -93,20 +114,6 @@ 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()
|
||||
}
|
||||
|
@ -123,7 +130,7 @@ func (e *Engine) renderBlock(block *Block) {
|
|||
switch block.Alignment {
|
||||
case Right:
|
||||
text, length := block.renderSegments()
|
||||
if padText, OK := shouldFill(length); OK {
|
||||
if padText, OK := e.shouldFill(block, length); OK {
|
||||
e.write(padText)
|
||||
}
|
||||
e.writeANSI(e.Ansi.CarriageForward())
|
||||
|
|
Loading…
Reference in a new issue