| Date: Sat, 27 Jan 2018 18:03:17 +0100
Handle terminal resizing
Diffstat:
M common.h | 1 +
M sacc.c | 9 ++++++++-
M ui_ti.c | 12 ++++++++++++
M ui_txt.c | 33 +++++++++++++++++++++----------
4 files changed, 44 insertions(+), 11 deletions(-)
--- |
| @@ -30,3 +30,4 @@ void uistatus(char *fmt, ...);
void uicleanup(void);
char *uiprompt(char *fmt, ...);
void uisetup(void);
+void uisigwinch(int signal); |
| @@ -3,6 +3,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -779,6 +780,7 @@ cleanup(void)
static void
setup(void)
{
+ struct sigaction sa;
int fd;
setenv("PAGER", "more", 0);
@@ -793,8 +795,13 @@ setup(void)
die("open: /dev/null: %s", strerror(errno));
if (mkdir(tmpdir, S_IRWXU) < 0 && errno != EEXIST)
die("mkdir: %s: %s", tmpdir, strerror(errno));
- if(interactive = isatty(1))
+ if(interactive = isatty(1)) {
uisetup();
+ sigemptyset(&sa.sa_mask);
+ sa.sa_handler = uisigwinch;
+ sa.sa_flags = SA_RESTART;
+ sigaction(SIGWINCH, &sa, NULL);
+ }
}
int |
| @@ -16,6 +16,7 @@
static char bufout[256];
static struct termios tsave;
static struct termios tsacc;
+static Item *curentry;
#if defined(__NetBSD__)
#undef tparm
#define tparm tiparm
@@ -244,6 +245,8 @@ uidisplay(Item *entry)
!(entry->type == '1' || entry->type == '+' || entry->type == '7'))
return;
+ curentry = entry;
+
putp(tparm(clear_screen));
displaystatus(entry);
@@ -536,3 +539,12 @@ uiselectitem(Item *entry)
}
}
}
+
+void
+uisigwinch(int signal)
+{
+ setupterm(NULL, 1, NULL);
+ putp(tparm(change_scroll_region, 0, lines-2));
+
+ uidisplay(curentry);
+} |
| @@ -11,6 +11,8 @@
#include "common.h"
static char bufout[256];
+static Item *curentry;
+static char cmd;
int lines, columns;
static void
@@ -148,6 +150,8 @@ uidisplay(Item *entry)
!(dir = entry->dat))
return;
+ curentry = entry;
+
items = dir->items;
nitems = dir->nitems;
nlines = dir->printoff + lines;
@@ -218,7 +222,6 @@ Item *
uiselectitem(Item *entry)
{
Dir *dir;
- static char c;
char buf[BUFSIZ], *sstr, nl;
int item, nitems;
@@ -228,9 +231,9 @@ uiselectitem(Item *entry)
nitems = dir ? dir->nitems : 0;
for (;;) {
- if (!c)
- c = 'h';
- printstatus(entry, c);
+ if (!cmd)
+ cmd = 'h';
+ printstatus(entry, cmd);
fflush(stdout);
if (!fgets(buf, sizeof(buf), stdin)) {
@@ -238,28 +241,28 @@ uiselectitem(Item *entry)
return NULL;
}
if (isdigit(*buf)) {
- c = '\0';
+ cmd = '\0';
nl = '\0';
if (sscanf(buf, "%d%c", &item, &nl) != 2 || nl != '\n')
item = -1;
} else if (!strcmp(buf+1, "\n")) {
item = -1;
- c = *buf;
+ cmd = *buf;
} else if (*buf == '/') {
for (sstr = buf+1; *sstr && *sstr != '\n'; ++sstr)
;
*sstr = '\0';
sstr = buf+1;
- c = *buf;
+ cmd = *buf;
} else if (isdigit(*(buf+1))) {
nl = '\0';
if (sscanf(buf+1, "%d%c", &item, &nl) != 2 || nl != '\n')
item = -1;
else
- c = *buf;
+ cmd = *buf;
}
- switch (c) {
+ switch (cmd) {
case '\0':
break;
case 'q':
@@ -301,7 +304,7 @@ uiselectitem(Item *entry)
help();
continue;
default:
- c = 'h';
+ cmd = 'h';
continue;
}
@@ -314,3 +317,13 @@ uiselectitem(Item *entry)
return entry->entry;
}
+
+void
+uisigwinch(int signal)
+{
+ uisetup();
+ putchar('\n');
+ uidisplay(curentry);
+ printstatus(curentry, cmd);
+ fflush(stdout);
+} |