]> git.mdlowis.com Git - archive/afm.git/commitdiff
Resize when terminal is resized
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 17 Jul 2014 02:58:33 +0000 (22:58 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 17 Jul 2014 02:58:33 +0000 (22:58 -0400)
source/main.c

index 9d7eeaedb0b515682cbd8a066a8b4f7323b748e6..392118c40de5be418db19e676ca4a49687213110 100644 (file)
@@ -1,5 +1,6 @@
 #include <ncurses.h>
 #include <stdbool.h>
+#include <signal.h>
 
 static bool Running = true;
 //static int Term_X = 0;
@@ -27,22 +28,33 @@ void destroy_window(WINDOW* p_win) {
     delwin(p_win);
 }
 
+void update_screen(void) {
+    endwin();
+    /* Create the left and right windows */
+    WindowLeft  = create_window(0,0,LINES,COLS/2);
+    wprintw(WindowLeft,  "\rLeft");
+    wrefresh(WindowLeft);
+    WindowRight = create_window(COLS/2,0,LINES,COLS/2);
+    wprintw(WindowRight, "\rRight");
+    wrefresh(WindowRight);
+}
+
+void handle_signal(int sig) {
+    update_screen();
+    signal(SIGWINCH, handle_signal);
+}
+
 int main(int argc, char** argv) {
+    /* Handle terminal resizing */
+    signal(SIGWINCH, handle_signal);
     /* Initialize ncurses and user input settings */
     initscr();
     raw();
     keypad(stdscr, TRUE);
     noecho();
     refresh();
-    /* Create the left and right windows */
-    WindowLeft  = create_window(0,0,LINES,COLS/2);
-    WindowRight = create_window(COLS/2,0,LINES,COLS/2);
     while(Running) {
-        //getmaxyx(stdscr, Term_Y, Term_X);
-        wprintw(WindowLeft,  "\rLeft");
-        wprintw(WindowRight, "\rRight");
-        wrefresh(WindowLeft);
-        wrefresh(WindowRight);
+        update_screen();
         handle_input(getch());
     }
     destroy_window(WindowLeft);