summaryrefslogtreecommitdiff
path: root/console.c
diff options
context:
space:
mode:
Diffstat (limited to 'console.c')
-rw-r--r--console.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/console.c b/console.c
new file mode 100644
index 0000000..558184f
--- /dev/null
+++ b/console.c
@@ -0,0 +1,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;
+}