summaryrefslogtreecommitdiff
path: root/console.c
blob: 2ac2068b7914f01e8e49f0d06e90d182d396afb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <sys/ioctl.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>

int getTerminalSize(unsigned short *width, unsigned short *height) {
	struct winsize ws;

	if (ioctl(0,TIOCGWINSZ,&ws) != 0) {
		fprintf(stderr,"TIOCGWINSZ:%s\n",strerror(errno));
		return -1;
	}

	*width = ws.ws_col;
	*height = ws.ws_row;

	return 1;
}