Skip to content

Instantly share code, notes, and snippets.

@abiriadev
Created November 29, 2023 07:51
Show Gist options
  • Save abiriadev/080c3353ada9004999c9a9ccdd6218e5 to your computer and use it in GitHub Desktop.
Save abiriadev/080c3353ada9004999c9a9ccdd6218e5 to your computer and use it in GitHub Desktop.
import (
"fmt"
"golang.org/x/sys/unix"
)
func tCol() (int, error) {
var ws unix.Winsize
_, _, err := unix.Syscall(
unix.SYS_IOCTL,
uintptr(0),
uintptr(unix.TIOCGWINSZ),
uintptr(unsafe.Pointer(&ws)),
)
if err != 0 {
return 0, err
}
return int(ws.Col), nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment