mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-09 20:44:03 -08:00
fix: render newline correctly cross platform/shell
Powershell has an issue rendering multiline prompts when it comes to PSReadline on MacOS. To mitigate that, we make it a multiline prompt by moving the cursor all the way to the end. That way, PSReadline believes this is still a one line prompt and everything works as expected. https://github.com/PowerShell/PowerShell/issues/3687
This commit is contained in:
parent
5c4af19d90
commit
6fd9f0bdd9
22
engine.go
22
engine.go
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
|
@ -122,34 +121,31 @@ func (e *engine) lenWithoutANSI(str string) int {
|
|||
return count
|
||||
}
|
||||
|
||||
func (e *engine) string() string {
|
||||
var buffer bytes.Buffer
|
||||
defer buffer.Reset()
|
||||
func (e *engine) render() {
|
||||
for _, block := range e.settings.Blocks {
|
||||
// if line break, append a line break
|
||||
if block.Type == LineBreak {
|
||||
buffer.WriteString("\x1b[1B")
|
||||
fmt.Printf("\x1b[%dC ", 1000)
|
||||
continue
|
||||
}
|
||||
if block.LineOffset < 0 {
|
||||
buffer.WriteString(fmt.Sprintf("\x1b[%dF", -block.LineOffset))
|
||||
fmt.Printf("\x1b[%dF", -block.LineOffset)
|
||||
} else if block.LineOffset > 0 {
|
||||
buffer.WriteString(fmt.Sprintf("\x1b[%dB", block.LineOffset))
|
||||
fmt.Printf("\x1b[%dB", block.LineOffset)
|
||||
}
|
||||
switch block.Alignment {
|
||||
case Right:
|
||||
buffer.WriteString(fmt.Sprintf("\x1b[%dC", 1000))
|
||||
fmt.Printf("\x1b[%dC", 1000)
|
||||
blockText := e.renderBlockSegments(block)
|
||||
buffer.WriteString(fmt.Sprintf("\x1b[%dD", e.lenWithoutANSI(blockText)+e.settings.RightSegmentOffset))
|
||||
buffer.WriteString(blockText)
|
||||
fmt.Printf("\x1b[%dD", e.lenWithoutANSI(blockText)+e.settings.RightSegmentOffset)
|
||||
fmt.Print(blockText)
|
||||
default:
|
||||
buffer.WriteString(e.renderBlockSegments(block))
|
||||
fmt.Print(e.renderBlockSegments(block))
|
||||
}
|
||||
}
|
||||
if e.settings.EndSpaceEnabled {
|
||||
buffer.WriteString(" ")
|
||||
fmt.Print(" ")
|
||||
}
|
||||
return buffer.String()
|
||||
}
|
||||
|
||||
func (e *engine) reset() {
|
||||
|
|
Loading…
Reference in a new issue