blob: 558184fe83c26d547e234a8d07482eb36255f691 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#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;
printf("Console width: %d, height: %d\n", *width, *height);
return 1;
}
|