Codebase list golang-github-vbauerster-mpb / 6f4a221 cwriter / writer_posix.go
6f4a221

Tree @6f4a221 (Download .tar.gz)

writer_posix.go @6f4a221raw · history · blame

// +build !windows

package cwriter

import (
	"golang.org/x/sys/unix"
)

func (w *Writer) clearLines() error {
	return w.ansiCuuAndEd()
}

// GetSize returns the dimensions of the given terminal.
func GetSize(fd int) (width, height int, err error) {
	ws, err := unix.IoctlGetWinsize(fd, unix.TIOCGWINSZ)
	if err != nil {
		return -1, -1, err
	}
	return int(ws.Col), int(ws.Row), nil
}

// IsTerminal returns whether the given file descriptor is a terminal.
func IsTerminal(fd int) bool {
	_, err := unix.IoctlGetTermios(fd, ioctlReadTermios)
	return err == nil
}