get rid of slang
[apps/madmutt.git] / lib-ui / resize.c
1 /*
2  * Copyright notice from original mutt:
3  * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
4  *
5  * This file is part of mutt-ng, see http://www.muttng.org/.
6  * It's licensed under the GNU General Public License,
7  * please see the file GPL in the top level source directory.
8  */
9
10 #include <lib-lib/lib-lib.h>
11
12 #if defined(HAVE_RESIZETERM)
13
14 #include <termios.h>
15 #ifdef HAVE_SYS_IOCTL_H
16 #  include <sys/ioctl.h>
17 #elif defined(HAVE_IOCTL_H)
18 #  include <ioctl.h>
19 #endif
20
21 #include <lib-ui/curses.h>
22 #include "mutt.h"
23
24 /* this routine should be called after receiving SIGWINCH */
25 void mutt_resize_screen (void)
26 {
27   char *cp;
28   int fd;
29   struct winsize w;
30
31   int rows, cols;
32
33   rows = -1;
34   cols = -1;
35   if ((fd = open ("/dev/tty", O_RDONLY)) != -1) {
36     if (ioctl (fd, TIOCGWINSZ, &w) != -1) {
37       rows = w.ws_row;
38       cols = w.ws_col;
39     }
40     close (fd);
41   }
42   if (rows <= 0) {
43     if ((cp = getenv ("LINES")) != NULL) {
44       rows = atoi (cp);
45     }
46     else
47       rows = 24;
48   }
49   if (cols <= 0) {
50     if ((cp = getenv ("COLUMNS")) != NULL)
51       cols = atoi (cp);
52     else
53       cols = 80;
54   }
55   resizeterm (rows, cols);
56 }
57
58 #endif /* defined(HAVE_RESIZETERM) */