Skip to content

Commit

Permalink
fix: fixed buggy behavior on windows (#20)
Browse files Browse the repository at this point in the history
* fix: fixed buggy behavior on windows

* fix: fixed buggy behavior on windows

* fix: fixed buggy behavior on windows
  • Loading branch information
MarvinJWendt authored Jul 18, 2023
1 parent ce71155 commit 9154cbc
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion area.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cursor
import (
"fmt"
"os"
"runtime"
"strings"
)

Expand Down Expand Up @@ -43,8 +44,23 @@ func (area *Area) Update(content string) {

SetTarget(area.writer) // Temporary set the target to the Area's writer so we can use the cursor functions
area.Clear()

lines := strings.Split(content, "\n")
fmt.Fprintln(area.writer, strings.Repeat("\n", len(lines)-1)) // This appends space if the terminal is at the bottom
Up(len(lines))
SetTarget(oldWriter) // Reset the target to the old writer
fmt.Fprintln(area.writer, content)

// Workaround for buggy behavior on Windows
if runtime.GOOS == "windows" {
for _, line := range lines {
fmt.Fprint(area.writer, line)
StartOfLineDown(1)
}
} else {
for _, line := range lines {
fmt.Fprintln(area.writer, line)
}
}

height = 0
area.height = len(strings.Split(content, "\n"))
Expand Down

0 comments on commit 9154cbc

Please sign in to comment.