support window resizing in curses mode
authorNathan Bryant <loanshark@uncensored.citadel.org>
Thu, 14 Mar 2002 04:24:20 +0000 (04:24 +0000)
committerNathan Bryant <loanshark@uncensored.citadel.org>
Thu, 14 Mar 2002 04:24:20 +0000 (04:24 +0000)
citadel/ChangeLog
citadel/citadel.c
citadel/citadel_decls.h
citadel/client_chat.c
citadel/commands.c
citadel/screen.c
citadel/screen.h

index d0743d7971288c5bc9cede9e851e121929369212..6dcf25e69e236c0190886059dfe4ae3865dfccf9 100644 (file)
@@ -1,4 +1,7 @@
  $Log$
+ Revision 590.153  2002/03/14 04:24:20  nbryant
+ support window resizing in curses mode
+
  Revision 590.152  2002/03/13 04:11:11  nbryant
  fix up minor gotcha introduced by fgets change
 
@@ -3502,4 +3505,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import 
-
index 7f5b7dd43ec84b4e3e34e760a99d7f4aa8c3fc53..59819c905dcf2ead18320bc1f924053bf897ac7b 100644 (file)
@@ -689,13 +689,10 @@ void check_screen_dims(void)
                unsigned short ypixels;         /* pixels */
        } xwinsz;
 
-       if (scr_set_windowsize())
-               return;
-
        if (have_xterm) {       /* dynamically size screen if on an xterm */
                if (ioctl(0, TIOCGWINSZ, &xwinsz) == 0) {
                        if (xwinsz.height)
-                               screenheight = (int) xwinsz.height;
+                               screenheight = is_curses_enabled() ? (int)xwinsz.height - 1 : (int) xwinsz.height;
                        if (xwinsz.width)
                                screenwidth = (int) xwinsz.width;
                }
@@ -950,7 +947,10 @@ int main(int argc, char **argv)
        sttybbs(SB_NO_INTR);    /* Install the new ones */
        signal(SIGHUP, dropcarr);       /* Cleanup gracefully if carrier is dropped */
        signal(SIGTERM, dropcarr);      /* Cleanup gracefully if terminated */
-       signal(SIGCONT, catch_sigcont);         /* Catch SIGCONT so we can reset terminal */
+       signal(SIGCONT, catch_sigcont); /* Catch SIGCONT so we can reset terminal */
+#ifdef SIGWINCH
+       signal(SIGWINCH, scr_winch);    /* Window resize signal */
+#endif
 
 #ifdef HAVE_OPENSSL
        arg_encrypt = RC_DEFAULT;
index ce789ac1eda36e6433e329c6d6bd695a34cd3ae6..94f9d260d49b1d5c8d49ab0ff507ab784f7c65f0 100644 (file)
@@ -27,3 +27,4 @@ void logoff(int code);
 void formout(char *name);
 void sighandler(int which_sig);
 void do_system_configuration(void);
+extern int secure;
index 482bcdc265dd2ac0a0056df5e35c346389a1b6c2..7c4b02c56055ee8e50eaf2c5175c1745cffaf7b1 100644 (file)
@@ -111,7 +111,7 @@ void chatmode(void)
                        goto RCL;
                }
                if (FD_ISSET(0, &rfds)) {
-                       ch = scr_getc();
+                       ch = scr_getc(SCR_BLOCK);
                        if ((ch == 10) || (ch == 13)) {
                                send_complete_line = 1;
                        } else if ((ch == 8) || (ch == 127)) {
index 69a7340cf4338621983be4c2982ce8c19147f4fc..ade3f26d1c37ad88e3d96a236711118a3efb98d2 100644 (file)
@@ -460,7 +460,9 @@ int inkey(void)
                 * necessary and then waits again.
                 */
                do {
+                       scr_set_windowsize();
                        do_keepalive();
+                       scr_set_windowsize();
 
                        FD_ZERO(&rfds);
                        FD_SET(0, &rfds);
@@ -473,7 +475,7 @@ int inkey(void)
                /* At this point, there's input, so fetch it.
                 * (There's a hole in the bucket...)
                 */
-               a = scr_getc();
+               a = scr_getc(SCR_NOBLOCK);
                if (a == 127)
                        a = 8;
                if (a > 126)
@@ -483,6 +485,12 @@ int inkey(void)
                if (((a != 4) && (a != 10) && (a != 8) && (a != NEXT_KEY) && (a != STOP_KEY))
                    && ((a < 32) || (a > 126)))
                        a = 0;
+
+#if defined(HAVE_CURSES_H) || defined(HAVE_NCURSES_H)
+               if (a == ERR)
+                       a = 0;
+#endif
+
        } while (a == 0);
        return (a);
 }
index c8cb29603d226c3b9f9352fbb6c92bcb952ebce2..2c266b06db8300c998ea2675583ae14b7558676e 100644 (file)
@@ -5,12 +5,8 @@
  */
 
 #include "sysdep.h"
-#ifdef HAVE_NCURSES_H
-#include <ncurses.h>
-#elif defined(HAVE_CURSES_H)
-#include <curses.h>
-#endif
 #include <stdio.h>
+#include <signal.h>
 #include <string.h>
 #include <stdarg.h>
 #include <unistd.h>
@@ -27,6 +23,7 @@
 #include "citadel.h"
 #include "commands.h"
 #include "screen.h"
+#include "citadel_decls.h"
 
 #ifdef HAVE_CURSES_H
 static SCREEN *myscreen = NULL;
@@ -279,18 +276,27 @@ int sln_printf_if(char *fmt, ...)
 }
 
 
-int scr_getc(void)
+int scr_getc(int delay)
 {
   char buf;
+
 #ifdef HAVE_CURSES_H
-       if (mainwindow)
+       if (mainwindow) {
+               wtimeout(mainwindow, delay);
                return wgetch(mainwindow);
+       }
 #endif
+
   buf = '\0';
   read (0, &buf, 1);
        return buf;
 }
 
+/* the following is unused and looks broken, but there may
+   be some input problems still lurking in curses mode, so
+   i'll leave it blocked out for now for informational
+   purposes. */
+#if 0
 int scr_blockread(void)
   {
     int a = 0;
@@ -307,6 +313,7 @@ int scr_blockread(void)
 #endif
     return a;
   }
+#endif /* 0 */
 
 /*
  * scr_putc() outputs a single character
@@ -397,33 +404,43 @@ void sln_flush(void)
                fflush(stdout);
 }
 
+static volatile int caught_sigwinch = 0;
 
-int scr_set_windowsize(void)
+/*
+ * this is not supposed to be called from a signal handler.
+ */
+int scr_set_windowsize()
 {
 #ifdef HAVE_CURSES_H
-       int y, x;
-
-       if (mainwindow) {
-               getmaxyx(mainwindow, y, x);
-               screenheight = y;
-               screenwidth = x;
+       if (mainwindow && caught_sigwinch) {
+               caught_sigwinch = 0;
+               resizeterm(screenheight + 1, screenwidth);
+               wresize(mainwindow, screenheight, screenwidth);
+               wresize(statuswindow, 1, screenwidth);
+               mvwin(statuswindow, screenheight, 0);
+               status_line(serv_info.serv_humannode, serv_info.serv_bbs_city,
+                            room_name, secure, -1);
+               wnoutrefresh(mainwindow);
+               wnoutrefresh(statuswindow);
+               doupdate();
                return 1;
        }
 #endif /* HAVE_CURSES_H */
        return 0;
 }
 
-
 /*
  * scr_winch() handles window size changes from SIGWINCH
  * resizes all our windows for us
  */
-RETSIGTYPE scr_winch(void)
+RETSIGTYPE scr_winch(int signum)
 {
-#ifdef HAVE_CURSES_H
-       /* FIXME: not implemented */
-#endif
+       /* if we receive this signal, we must be running
+          in a terminal that supports resizing. */
+       have_xterm = 1;
+       caught_sigwinch = 1;
        check_screen_dims();
+       signal(SIGWINCH, scr_winch);
 }
 
 
index 9e565a006a00df883bf3de53988f0b5e26fd8995..3c47d710f28ad1e6e3ef2366c8d9f1d8a7f925dc 100644 (file)
@@ -1,5 +1,13 @@
 /* $Id$ */
 
+/* client code may need the ERR define: */
+
+#ifdef HAVE_NCURSES_H
+#include <ncurses.h>
+#elif defined(HAVE_CURSES_H)
+#include <curses.h>
+#endif
+
 void status_line(const char *humannode, const char *bbs_city,
                 const char *room_name, int secure, int newmailcount);
 void screen_new(void);
@@ -10,7 +18,11 @@ int scr_printf(char *fmt, ...);
 int err_printf(char *fmt, ...);
 int sln_printf(char *fmt, ...);
 int sln_printf_if(char *fmt, ...);
-int scr_getc(void);
+
+#define SCR_NOBLOCK 0
+#define SCR_BLOCK -1
+int scr_getc(int delay);
+
 int scr_putc(int c);
 int sln_putc(int c);
 int scr_color(int colornum);
@@ -22,3 +34,4 @@ void windows_new(void);
 void windows_delete(void);
 int scr_blockread(void);
 int is_curses_enabled(void);
+RETSIGTYPE scr_winch(int signum);