Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed buggy behavior on windows #20

Merged
merged 4 commits into from
Jul 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
MarvinJWendt marked this conversation as resolved.
Show resolved Hide resolved
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
Loading