mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-10 04:54:03 -08:00
fix(engine): do not print sequential newlines on no content
relates to #4182
This commit is contained in:
parent
7eef6ef82d
commit
669521c8f7
|
@ -164,7 +164,7 @@ func (e *Engine) getTitleTemplateText() string {
|
|||
return ""
|
||||
}
|
||||
|
||||
func (e *Engine) renderBlock(block *Block, cancelNewline bool) {
|
||||
func (e *Engine) renderBlock(block *Block, cancelNewline bool) bool {
|
||||
defer e.patchPowerShellBleed()
|
||||
|
||||
// This is deprecated but we leave it in to not break configs
|
||||
|
@ -177,7 +177,7 @@ func (e *Engine) renderBlock(block *Block, cancelNewline bool) {
|
|||
if !cancelNewline {
|
||||
e.newline()
|
||||
}
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
// when in bash, for rprompt blocks we need to write plain
|
||||
|
@ -189,7 +189,7 @@ func (e *Engine) renderBlock(block *Block, cancelNewline bool) {
|
|||
}
|
||||
|
||||
if !block.Enabled() {
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
// do not print a newline to avoid a leading space
|
||||
|
@ -203,7 +203,7 @@ func (e *Engine) renderBlock(block *Block, cancelNewline bool) {
|
|||
|
||||
// do not print anything when we don't have any text
|
||||
if length == 0 {
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
switch block.Type { //nolint:exhaustive
|
||||
|
@ -215,11 +215,11 @@ func (e *Engine) renderBlock(block *Block, cancelNewline bool) {
|
|||
if block.Alignment == Left {
|
||||
e.currentLineLength += length
|
||||
e.write(text)
|
||||
return
|
||||
return true
|
||||
}
|
||||
|
||||
if block.Alignment != Right {
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
space, OK := e.canWriteRightBlock(false)
|
||||
|
@ -234,7 +234,7 @@ func (e *Engine) renderBlock(block *Block, cancelNewline bool) {
|
|||
e.write(padText)
|
||||
}
|
||||
e.currentLineLength = 0
|
||||
return
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -246,7 +246,7 @@ func (e *Engine) renderBlock(block *Block, cancelNewline bool) {
|
|||
if padText, OK := e.shouldFill(block.Filler, space, length); OK {
|
||||
e.write(padText)
|
||||
e.write(text)
|
||||
return
|
||||
return true
|
||||
}
|
||||
|
||||
var prompt string
|
||||
|
@ -262,6 +262,8 @@ func (e *Engine) renderBlock(block *Block, cancelNewline bool) {
|
|||
e.rprompt = text
|
||||
e.rpromptLength = length
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (e *Engine) patchPowerShellBleed() {
|
||||
|
|
|
@ -28,13 +28,23 @@ func (e *Engine) Primary() string {
|
|||
|
||||
// cache a pointer to the color cycle
|
||||
cycle = &e.Config.Cycle
|
||||
var cancelNewline, didRender bool
|
||||
|
||||
for i, block := range e.Config.Blocks {
|
||||
var cancelNewline bool
|
||||
// do not print a leading newline when we're at the first row and the prompt is cleared
|
||||
if i == 0 {
|
||||
row, _ := e.Env.CursorPosition()
|
||||
cancelNewline = e.Env.Flags().Cleared || e.Env.Flags().PromptCount == 1 || row == 1
|
||||
}
|
||||
e.renderBlock(block, cancelNewline)
|
||||
|
||||
// skip setting a newline when we didn't print anything yet
|
||||
if i != 0 {
|
||||
cancelNewline = !didRender
|
||||
}
|
||||
|
||||
if e.renderBlock(block, cancelNewline) {
|
||||
didRender = true
|
||||
}
|
||||
}
|
||||
|
||||
if len(e.Config.ConsoleTitleTemplate) > 0 && !e.Env.Flags().Plain {
|
||||
|
|
Loading…
Reference in a new issue