gophra

gopher client for plan9
git clone git://nsmpr.xyz/gophra.git
Log | Files | Refs

commit 8e1a3abd20fe784d91368edc1f53cd8dde8a75f2
parent 67e49196331c4e86c31db8dad6a80156cf9b9900
Author: glenda <glenda@9front.local>
Date:   Sat,  2 May 2020 18:10:23 +0000

history

Diffstat:
MTODO | 3+--
Mgophra.c | 45++++++++++++++++++++++++++++++++++-----------
2 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/TODO b/TODO @@ -1,4 +1,3 @@ * README * man page -* history -* image view +* move loading into separate thread diff --git a/gophra.c b/gophra.c @@ -21,15 +21,21 @@ struct Text { long size; } text; +typedef struct History History; +struct History { + char addr[255]; + char path[255]; + History *prev; +}; + +History hzero, *hp; + Image *Iborder, *Iwbg, *Iwfg, *Iwfgl, *Istatus; Rectangle rstatus, rw; char status[256], path[256], addr[256], type; -char history[64][256]; -int hc; - char *tmpfile = "/tmp/gophra.tmp"; long scroll; @@ -85,10 +91,14 @@ threadmain(int argc, char **argv) mpress = 0; scroll = 0; - hc = 0; + hp = &hzero; + snprint(status, 255, "gophra!"); - if (argv[0] != 0) loadtext(argv[0], ""); + if (argv[0] != 0) { + strncpy(hzero.addr, argv[0], 256); + loadtext(argv[0], ""); + } calcrects(); drawborder(); @@ -155,10 +165,14 @@ threadmain(int argc, char **argv) sline = (mv.xy.y - rw.min.y) / font->height + scroll; s = getline(sline); - + extracturl(s); handlelink(); if (s != 0) free(s); } + if (mv.buttons == 4) { + mpress = 1; + back(); + } break; case 2: /* resize */ if(getwindow(display, Refnone) < 0) @@ -183,10 +197,13 @@ usage(void) void back(void) { - if (hc == 0) return; - hc--; - // todo: extract addr and path from history - //loadtext + History *hold; + if (hp == &hzero) return; + scroll = 0; + hold = hp; + hp = hp->prev; + free(hold); + loadtext(hp->addr, hp->path); drawmenu(); flushimage(display, 1); } @@ -341,12 +358,18 @@ extracturl(char *s) void handlelink(void) { + History *hnew; switch (type) { case '0': save(); proccreate(runhold, 0, 1024 * 8); break; case '1': + hnew = malloc(sizeof(History)); + hnew->prev = hp; + hp = hnew; + strncpy(hp->addr, addr, 256); + strncpy(hp->path, path, 256); loadtext(addr, path); scroll = 0; drawmenu(); @@ -375,7 +398,7 @@ loadtext(char *addr, char *path) write(dcfd, path, strlen(path)); write(dcfd, "\n", 1); } else { - snprint(status, 255, "failed to dial %s", addr); + snprint(status, 255, "failed to dial \"%s\"", addr); drawstatus(); flushimage(display, 1); return -1;