<commit_before>// Copyright 2015 go-termios Author. All Rights Reserved.
// https://github.com/go-termios/termios
// Author: <NAME> <<EMAIL>>

package sys

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

// winSize mirrors struct winsize in the C header.
// The following declaration matches struct winsize in the headers of
// Linux and FreeBSD.
type winSize struct {
	row    uint16
	col    uint16
	Xpixel uint16
	Ypixel uint16
}

// GetWinsize queries the size of the terminal referenced by
// the given file descriptor.

func GetWinsize(fd int) (row, col int) {
	ws := winSize{}
	if err := ioctl(uintptr(fd), unix.TIOCGWINSZ, unsafe.Pointer(&ws)); err != nil {
		fmt.Printf("error in winSize: %v", err)
		return -1, -1
	}
	return int(ws.row), int(ws.col)
}<commit_msg>Handled special case when window size equals zero. (#349)<commit_after>// Copyright 2015 go-termios Author. All Rights Reserved.
// https://github.com/go-termios/termios
// Author: <NAME> <<EMAIL>>

package sys

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

// winSize mirrors struct winsize in the C header.
// The following declaration matches struct winsize in the headers of
// Linux and FreeBSD.
type winSize struct {
	row    uint16
	col    uint16
	Xpixel uint16
	Ypixel uint16
}

// GetWinsize queries the size of the terminal referenced by
// the given file descriptor.

func GetWinsize(fd int) (row, col int) {
	ws := winSize{}
	if err := ioctl(uintptr(fd), unix.TIOCGWINSZ, unsafe.Pointer(&ws)); err != nil {
		fmt.Printf("error in winSize: %v", err)
		return -1, -1
	}

	// Pick up a reasonable value for row and col
	// if they equal zero in special case,
	// e.g. serial console
	if ws.col == 0 {
		ws.col = 80
	}
	if ws.row == 0 {
		ws.row = 24
	}

	return int(ws.row), int(ws.col)
}
{'fraction_non_alphanumeric': 0.1274564851207187, 'fraction_numerical': 0.020774845592363842, 'mean_word_length': 3.273381294964029, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6668090', 'n_tokens_mistral': 672, 'n_tokens_neox': 620, 'n_words': 215}