Winsize ioctl terminal size detection example
authorHarvie <tomas@mudrunka.cz>
Sun, 6 Nov 2011 13:41:41 +0000 (14:41 +0100)
committerHarvie <tomas@mudrunka.cz>
Sun, 6 Nov 2011 13:41:41 +0000 (14:41 +0100)
c/winsize.c [new file with mode: 0644]

diff --git a/c/winsize.c b/c/winsize.c
new file mode 100644 (file)
index 0000000..03c1f7c
--- /dev/null
@@ -0,0 +1,14 @@
+#include <stdio.h>
+#include <sys/ioctl.h>
+
+static int get_win_size (int fd, struct winsize *win)
+{
+  int err = ioctl (fd, TIOCGWINSZ, (char *) win);
+  return err;
+}
+
+int main(void) {
+       struct winsize win;
+       if(!get_win_size(1, &win)) puts("Chyba!");
+       printf("%d %d :-)\n", win.ws_row, win.ws_col);
+}
This page took 0.184171 seconds and 4 git commands to generate.