fix: make newline compatible cross shell

When using PowerShell, "\n" isn't recognized as a newline character.
To resolve this, moving the cursor down 1 line is more interesting
as it will work in any shell using ANSI escape sequences (which we
depends upon).
This commit is contained in:
Jan De Dobbeleer 2020-09-15 09:11:47 +02:00
parent f3582d229e
commit 9b9405978e
10 changed files with 11 additions and 11 deletions

View file

@ -17,7 +17,7 @@
]
},
{
"type": "line-break"
"type": "newline"
},
{
"type": "prompt",

View file

@ -50,7 +50,7 @@
]
},
{
"type": "line-break"
"type": "newline"
},
{
"type": "prompt",

View file

@ -58,7 +58,7 @@
]
},
{
"type": "line-break"
"type": "newline"
},
{
"type": "prompt",

View file

@ -64,7 +64,7 @@
]
},
{
"type": "line-break"
"type": "newline"
},
{
"type": "prompt",

View file

@ -72,7 +72,7 @@
]
},
{
"type": "line-break"
"type": "newline"
},
{
"type": "prompt",

View file

@ -63,7 +63,7 @@
]
},
{
"type": "line-break"
"type": "newline"
},
{
"type": "prompt",

View file

@ -17,7 +17,7 @@
]
},
{
"type": "line-break"
"type": "newline"
},
{
"type": "prompt",

View file

@ -57,7 +57,7 @@
]
},
{
"type": "line-break"
"type": "newline"
},
{
"type": "prompt",

View file

@ -128,13 +128,13 @@ func (e *engine) string() string {
for _, block := range e.settings.Blocks {
// if line break, append a line break
if block.Type == LineBreak {
buffer.WriteString("\n")
buffer.WriteString("\x1b[1B")
continue
}
if block.LineOffset < 0 {
buffer.WriteString(fmt.Sprintf("\x1b[%dF", -block.LineOffset))
} else if block.LineOffset > 0 {
buffer.WriteString(fmt.Sprintf("\x1b[%dE", block.LineOffset))
buffer.WriteString(fmt.Sprintf("\x1b[%dB", block.LineOffset))
}
switch block.Alignment {
case Right:

View file

@ -26,7 +26,7 @@ const (
//Prompt writes one or more Segments
Prompt BlockType = "prompt"
//LineBreak creates a line break in the prompt
LineBreak BlockType = "line-break"
LineBreak BlockType = "newline"
//Left aligns left
Left BlockAlignment = "left"
//Right aligns right