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

constant scrolling when writing a line of size 2 * columns + 1 #32

Open
fkaleo opened this issue Apr 24, 2020 · 0 comments · May be fixed by #33
Open

constant scrolling when writing a line of size 2 * columns + 1 #32

fkaleo opened this issue Apr 24, 2020 · 0 comments · May be fixed by #33

Comments

@fkaleo
Copy link

fkaleo commented Apr 24, 2020

When writing a line of a very specific size, the next line will be written one line too low leading to undesired scrolling.
The following code will trigger the bug:

package main

import (
	"fmt"
	"os"
	"runtime"
	"strings"
	"syscall"
	"time"
	"unsafe"

	"github.com/gosuri/uilive"
)

type windowSize struct {
	rows uint16
	cols uint16
}

func getTermSize() (int, int) {
	var out *os.File
	var err error
	var sz windowSize
	if runtime.GOOS == "openbsd" {
		out, err = os.OpenFile("/dev/tty", os.O_RDWR, 0)
		if err != nil {
			return 0, 0
		}

	} else {
		out, err = os.OpenFile("/dev/tty", os.O_WRONLY, 0)
		if err != nil {
			return 0, 0
		}
	}
	_, _, _ = syscall.Syscall(syscall.SYS_IOCTL,
		out.Fd(), uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(&sz)))
	return int(sz.cols), int(sz.rows)
}

func main() {
	cols, _ := getTermSize()
	writer := uilive.New()

	for {
		_, _ = fmt.Fprintf(writer, "%s\n", strings.Repeat("b", cols*2+1))
		writer.Flush()
		time.Sleep(1000 * time.Millisecond)
	}
}
fkaleo added a commit to fkaleo/uilive that referenced this issue Apr 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant