commit 081653074e69ae028be354aee7eca0c178a34d96
parent b5c402515b3273d7889236698fea95dd57190326
Author: Quentin Rameau <quinq@fifth.space>
Date: Sun, 2 Jul 2017 18:55:57 +0200
Display text item via default PAGER
Diffstat:
M | sacc.c | | | 42 | +++++++++++++++++++++++++++++++++++++----- |
M | ui_ti.c | | | 46 | +++++++++++++++++++--------------------------- |
M | ui_txt.c | | | 37 | +++++++++++++++---------------------- |
3 files changed, 71 insertions(+), 54 deletions(-)
diff --git a/sacc.c b/sacc.c
@@ -9,6 +9,7 @@
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
+#include <sys/wait.h>
#include "common.h"
@@ -116,6 +117,28 @@ typedisplay(char t)
}
}
+static void
+displaytextitem(Item *item)
+{
+ FILE *pagerin;
+ int pid, wpid;
+
+ uicleanup();
+ switch (pid = fork()) {
+ case -1:
+ fprintf(stderr, "Couldn't fork.\n");
+ return;
+ case 0:
+ pagerin = popen("$PAGER", "we");
+ fputs(item->raw, pagerin);
+ exit(pclose(pagerin));
+ default:
+ while ((wpid = wait(NULL)) >= 0 && wpid != pid)
+ ;
+ }
+ uisetup();
+}
+
static char *
pickfield(char **raw, char sep)
{
@@ -303,7 +326,7 @@ dig(Item *entry, Item *item)
int sock;
if (item->raw) /* already in cache */
- return 1;
+ return item->type;
if (!item->entry)
item->entry = entry;
@@ -331,7 +354,7 @@ dig(Item *entry, Item *item)
return 0;
}
}
- return 1;
+ return item->type;
}
static void
@@ -340,12 +363,21 @@ delve(Item *hole)
Item *entry = hole;
while (hole) {
- if (dig(entry, hole)) {
- display(hole);
- } else {
+ switch (dig(entry, hole)) {
+ case '0':
+ displaytextitem(hole);
+ hole = entry;
+ break;
+ case '1':
+ break;
+ default:
fprintf(stderr, "Couldn't get %s:%s/%c%s\n", hole->host,
hole->port, hole->type, hole->selector);
+ hole = entry;
+ break;
}
+
+ display(hole);
entry = hole;
hole = selectitem(hole);
}
diff --git a/ui_ti.c b/ui_ti.c
@@ -48,38 +48,31 @@ display(Item *item)
Item **items;
size_t i, curln, lastln, nitems, printoff;
- if (item->type > '1')
+ if (item->type != '1')
return;
putp(tparm(clear_screen));
putp(tparm(save_cursor));
- switch (item->type) {
- case '0':
- puts(item->raw);
- break;
- case '1':
- items = item->dir->items;
- nitems = item->dir->nitems;
- printoff = item->printoff;
- curln = item->curline;
- lastln = printoff + lines;
-
- for (i = printoff; i < nitems && i < lastln; ++i) {
- if (item = items[i]) {
- if (i != printoff)
- putp(tparm(cursor_down));
- if (i == curln) {
- putp(tparm(save_cursor));
- putp(tparm(enter_standout_mode));
- }
- printitem(item);
- putp(tparm(column_address, 0));
- if (i == curln)
- putp(tparm(exit_standout_mode));
+ items = item->dir->items;
+ nitems = item->dir->nitems;
+ printoff = item->printoff;
+ curln = item->curline;
+ lastln = printoff + lines;
+
+ for (i = printoff; i < nitems && i < lastln; ++i) {
+ if (item = items[i]) {
+ if (i != printoff)
+ putp(tparm(cursor_down));
+ if (i == curln) {
+ putp(tparm(save_cursor));
+ putp(tparm(enter_standout_mode));
}
+ printitem(item);
+ putp(tparm(column_address, 0));
+ if (i == curln)
+ putp(tparm(exit_standout_mode));
}
- break;
}
putp(tparm(restore_cursor));
@@ -171,4 +164,4 @@ selectitem(Item *entry)
}
}
-}-
\ No newline at end of file
+}
diff --git a/ui_txt.c b/ui_txt.c
@@ -45,31 +45,24 @@ display(Item *item)
size_t i, lines, nitems;
int ndigits;
- if (item->type > '1')
+ if (item->type != '1')
return;
- switch (item->type) {
- case '0':
- puts(item->raw);
- break;
- case '1':
- items = item->dir->items;
- nitems = item->dir->nitems;
- lines = item->printoff + termlines();
- ndigits = (nitems < 10) ? 1 : (nitems < 100) ? 2 : 3;
-
- for (i = item->printoff; i < nitems && i < lines; ++i) {
- if (item = items[i]) {
- printf("%*d %-4s%c %s\n", ndigits, i+1,
- item->type != 'i' ?
- typedisplay(item->type) : "",
- item->type > '1' ? '|' : '+',
- items[i]->username);
- } else {
- printf("%*d !! |\n", ndigits, i+1);
- }
+ items = item->dir->items;
+ nitems = item->dir->nitems;
+ lines = item->printoff + termlines();
+ ndigits = (nitems < 10) ? 1 : (nitems < 100) ? 2 : 3;
+
+ for (i = item->printoff; i < nitems && i < lines; ++i) {
+ if (item = items[i]) {
+ printf("%*d %-4s%c %s\n", ndigits, i+1,
+ item->type != 'i' ?
+ typedisplay(item->type) : "",
+ item->type > '1' ? '|' : '+',
+ items[i]->username);
+ } else {
+ printf("%*d !! |\n", ndigits, i+1);
}
- break;
}
}