zygo

ncurses gopher client
Log | Files | Refs

commit 2ff02c0258f5de77c0b286fefb37f46563f30eaf
parent db7f21e0bbe7300ca50fd71ce250eae83bbc4dbc
Author: hhvn <dev@hhvn.uk>
Date:   Mon, 17 Jan 2022 02:16:48 +0000

Makefile config.def.h zygo.c zygo.1: documentation

Diffstat:
MMakefile | 7+++++--
Mconfig.def.h | 1-
Azygo.1 | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mzygo.c | 82++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------
4 files changed, 157 insertions(+), 20 deletions(-)

diff --git a/Makefile b/Makefile @@ -15,8 +15,10 @@ # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. PREFIX = /usr/local -BINDIR = /usr/local/bin +BINDIR = $(PREFIX)/bin +MANDIR = $(PREFIX)/man BIN = zygo +MAN = zygo.1 SRC += zygo.c OBJ = $(SRC:.c=.o) LDFLAGS = -lncurses @@ -34,9 +36,10 @@ zygo.o: config.h install: cp -f $(BIN) $(BINDIR)/$(BIN) + cp $(MAN) $(MANDIR)/man1/$(MAN) uninstall: - -rm -rf $(BINDIR)/$(BIN) + -rm -rf $(BINDIR)/$(BIN) $(MANDIR)/man1/$(MAN) clean: -rm -f $(OBJ) $(BIN) diff --git a/config.def.h b/config.def.h @@ -1,4 +1,3 @@ -static char *starturi = "gopher://hhvn.uk/1/git/o/zygo"; static char *plumber = "xdg-open"; static int parallelplumb = 0; static int stimeout = 5; diff --git a/zygo.1 b/zygo.1 @@ -0,0 +1,87 @@ +.\" zygo/zygo.1 +.\" +.\" Copyright (c) 2022 hhvn <dev@hhvn.uk> +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +.Dd COMMIT +.Dt zygo 1 +.Os +.Sh Name +.Nm zygo +.Nd ncurses gopher client +.Sh SYNOPSIS +.Nm +.Op Ar uri +.Sh DESCRIPTION +.Nm +is a rewrite of +.Xr cgo 1 +that tidies up a lot of stuff, +and has pager functionality using ncurses. +.Nm +supports gopher over tls, although it may be buggy. +The user may attempt to downgrade any tls connection if it fails. +.Sh INPUT +.Nm +is constantly reading input. +This input can be either an id to a link +(seen to the left of a line) or a command. +If a command requires an argument, +or the id is ambiguous, +the user must press enter. +.Sh COMMANDS +.Bl -compact -tag -width " " +.It : Ar uri +Go to +.Ar uri "." +.It / Ar query +Search forwards for +.Ar query "." +.It ? Ar query +Search backwards for +.Ar query "." +.It n +Search forwards with already present query. +.It N +Search backwards with already present query. +.It a Ar path +Append +.Ar path +to the current uri. +.It j +Scroll down one line. +.It ^D +Scroll down half a page. +.It k +Scroll up one line. +.It ^U +Scroll up half a page. +.It q +Quit. +.It < +Go back in history. +.It * +Reload page. +.It g +Go to top of page. +.It G +Go to bottom of page. +.It r +Go to root selector of current gopherhole. +.It +.El +.Sh SEE OTHER +.Xr cgo 1 +.Sh AUTHOR +.An hhvn Aq Mt dev@hhvn.uk diff --git a/zygo.c b/zygo.c @@ -627,13 +627,15 @@ draw_page(void) { attroff(A_COLOR); - move(0, 0); - zygo_assert(ui.scroll < list_len(&page)); - for (i = ui.scroll; i < list_len(&page) - 1 && y < LINES - 1; i++) - y += draw_line(list_get(&page, i), 1); - for (; y < LINES - 1; y++) { - move(y, 0); - clrtoeol(); + if (page) { + move(0, 0); + zygo_assert(ui.scroll < list_len(&page)); + for (i = ui.scroll; i < list_len(&page) - 1 && y < LINES - 1; i++) + y += draw_line(list_get(&page, i), 1); + for (; y < LINES - 1; y++) { + move(y, 0); + clrtoeol(); + } } } @@ -646,8 +648,10 @@ draw_bar(void) { move(LINES - 1, 0); clrtoeol(); - attron(COLOR_PAIR(PAIR_URI)); - printw(" %s ", elemtouri(current)); + if (current) { + attron(COLOR_PAIR(PAIR_URI)); + printw(" %s ", elemtouri(current)); + } attron(COLOR_PAIR(PAIR_BAR)); printw(" "); if (ui.wantinput) { @@ -668,6 +672,33 @@ draw_bar(void) { } void +manpage(void) { + pid_t pid; + int status; + char buf; + char *sh; + + endwin(); + + sh = getenv("SHELL"); + sh = sh ? sh : "/bin/sh"; + + pid = fork(); + if (pid == 0) + execlp(sh, sh, "-c", "man zygo", NULL); + assert(pid != -1); + waitpid(pid, &status, 0); + if (WEXITSTATUS(status) != 0) { + fprintf(stderr, "%s", "could not find manpage, press enter to continue..."); + fread(&buf, sizeof(char), 1, stdin); + } + + initscr(); + draw_page(); + draw_bar(); +} + +void syncinput(void) { int len; free(ui.arg); @@ -788,6 +819,10 @@ run(void) { } draw_bar(); } else { + /* Restrict keys for starting menu */ + if (!current && !(isdigit((int)c) || c == ':' || c == 'h' || c == 'q')) + continue; + switch (c) { case KEY_DOWN: case 'j': @@ -858,6 +893,9 @@ run(void) { draw_page(); draw_bar(); break; + case 'h': + manpage(); + break; /* link numbers */ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': @@ -895,7 +933,7 @@ run(void) { continue; gonum: - if (atoi(ui.arg) >= page->lastid || atoi(ui.arg) < 1) + if (atoi(ui.arg) > page->lastid || atoi(ui.arg) < 1) error("no such link: %d", atoi(ui.arg)); else go(list_idget(&page, atoi(ui.arg)), 1); @@ -922,24 +960,34 @@ sighandler(int signal) { int main(int argc, char *argv[]) { Elem *target; - char *targeturi; int i; + Elem start[] = { + {0, 'i', "Welcome to zygo"}, + {0, 'i', ""}, + {0, '1', "Type '1' to follow this link to gopher://hhvn.uk/1/git/o/zygo.", "/git/o/zygo", "hhvn.uk", "70"}, + {0, 'i', "Type ':' followed by a URI to go to said URI."}, + {0, 'i', "Type 'h' to read the man page"}, + {0, 'i', "Type 'q' to quit"}, + {0, 'i', ""}, + {0, 'i', "Only certain commands can be run if not veiwing a gopher menu."}, + {0, 'i', ""}, + {0, 'i', NULL}, + }; + + for (i = 0; start[i].desc; i++) + list_append(&page, &start[i]); switch (argc) { case 2: - targeturi = argv[1]; - break; + target = uritoelem(argv[1]); + go(target, 1); case 1: - targeturi = starturi; break; default: fprintf(stderr, "usage: %s [uri]\n", basename(argv[0])); exit(EXIT_FAILURE); } - target = uritoelem(targeturi); - go(target, 1); - setlocale(LC_ALL, ""); initscr(); noecho();