zygo

ncurses gopher client
Log | Files | Refs

commit ca802155b0d1c1545188398eabc45761129a4141
parent c04dabd91a450708febe54cb832fedfdac13afcc
Author: hhvn <dev@hhvn.uk>
Date:   Sun, 16 Jan 2022 17:28:41 +0000

config.h zygo.c zygo.h: better error handling

Diffstat:
Mconfig.h | 10+++++-----
Mzygo.c | 40+++++++++++++++++++++++++++++++++++++---
Mzygo.h | 7+++++--
3 files changed, 47 insertions(+), 10 deletions(-)

diff --git a/config.h b/config.h @@ -1,10 +1,10 @@ static char *starturi = "gopher://hhvn.uk"; -static short bar_pair[2] = {-1, 0}; -static short uri_pair[2] = {0, 7}; -static short cmd_pair[2] = {7, 0}; -static short arg_pair[2] = {-1, 0}; -static short err_pair[2] = {0, 88}; +static short bar_pair[2] = {-1, 0}; +static short uri_pair[2] = {0, 7}; +static short cmd_pair[2] = {7, 0}; +static short arg_pair[2] = {-1, 0}; +static short err_pair[2] = {160, 0}; static Scheme scheme[] = { {'i', " ", -1 }, diff --git a/zygo.c b/zygo.c @@ -24,6 +24,8 @@ #include <libgen.h> #include <assert.h> #include <locale.h> +#include <signal.h> +#include <unistd.h> #include <stdio.h> #include "zygo.h" #include "config.h" @@ -32,6 +34,7 @@ List *history = NULL; List *page = NULL; Elem *current = NULL; +int candraw = 1; int config[] = { [CONF_TLS_VERIFY] = 1, }; @@ -412,7 +415,9 @@ error(char *format, ...) { va_end(ap); addstr(" "); - getch(); + refresh(); + candraw = 0; + alarm(1); } Scheme * @@ -439,6 +444,11 @@ void draw_page(void) { int y = 0, i; + if (!candraw) + return; + + 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++) @@ -453,6 +463,9 @@ void draw_bar(void) { int savey, savex, x; + if (!candraw) + return; + move(LINES - 1, 0); clrtoeol(); attron(COLOR_PAIR(PAIR_URI)); @@ -498,6 +511,12 @@ run(void) { /* get_wch does refresh() for us */ while ((ret = get_wch(&c)) != ERR) { + if (!candraw) { + candraw = 1; + draw_page(); + draw_bar(); + } + if (c == KEY_RESIZE) { draw_page(); draw_bar(); @@ -518,7 +537,7 @@ run(void) { if (il == 0) { ui.wantinput = 0; } else { - ui.input[il--] = '\0'; + ui.input[--il] = '\0'; syncinput(); } } else if (c >= 32 && c < KEY_CODE_YES) { @@ -572,14 +591,27 @@ run(void) { il = 0; draw_bar(); break; + case '\n': + case 27: /* escape */ + case KEY_BACKSPACE: + break; default: - /* TODO: some sort of indicator */ + error("not bound"); break; } } } } +void +sighandler(int signal) { + if (signal == SIGALRM) { + candraw = 1; + draw_bar(); + refresh(); + } +} + int main(int argc, char *argv[]) { Elem *target; @@ -609,6 +641,8 @@ main(int argc, char *argv[]) { keypad(stdscr, TRUE); set_escdelay(10); + signal(SIGALRM, sighandler); + init_pair(PAIR_BAR, bar_pair[0], bar_pair[1]); init_pair(PAIR_URI, uri_pair[0], uri_pair[1]); init_pair(PAIR_CMD, cmd_pair[0], cmd_pair[1]); diff --git a/zygo.h b/zygo.h @@ -82,8 +82,6 @@ void list_append(List **l, Elem *e); Elem *list_get(List **l, size_t elem); size_t list_len(List **l); -int readline(char *buf, size_t count); -int go(Elem *e); /* Network functions * only works with one fd/ctx at @@ -103,3 +101,8 @@ void syncinput(void); /* Main loop */ void run(void); + +/* Misc */ +int readline(char *buf, size_t count); +int go(Elem *e); +void sighandler(int signal);