zygo

ncurses gopher client
Log | Files | Refs

commit 93d6cc1986793b3cdc208381cc7c1f9dc380292c
parent 457fc0808991db56371f5512d044cb049335feb7
Author: hhvn <dev@hhvn.uk>
Date:   Tue, 18 Jan 2022 17:13:44 +0000

zygo.c zygo.h: variable width padding for numbers

Diffstat:
Mzygo.c | 10++++++----
Mzygo.h | 2+-
2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/zygo.c b/zygo.c @@ -638,14 +638,14 @@ find(int backward) { } int -draw_line(Elem *e, int maxlines) { +draw_line(Elem *e, int nwidth) { int lc, cc; attron(COLOR_PAIR(PAIR_EID)); if (e->type != 'i' && e->type != '3') - printw("% 3d ", e->id); + printw("%1$ *2$d ", e->id, nwidth + 1); else - printw(" "); + printw("%1$ *2$s ", "", nwidth + 1); attroff(A_COLOR); attron(COLOR_PAIR(getscheme(e)->pair)); printw("%s ", getscheme(e)->name); @@ -662,6 +662,7 @@ draw_line(Elem *e, int maxlines) { void draw_page(void) { int y = 0, i; + int nwidth; if (!ui.candraw) return; @@ -669,10 +670,11 @@ draw_page(void) { attroff(A_COLOR); if (page) { + nwidth = digits(page->lastid); 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); + y += draw_line(list_get(&page, i), nwidth); for (; y < LINES - 1; y++) { move(y, 0); clrtoeol(); diff --git a/zygo.h b/zygo.h @@ -97,7 +97,7 @@ int net_close(void); void error(char *format, ...); Scheme *getscheme(Elem *e); void find(int backward); -int draw_line(Elem *e, int maxlines); +int draw_line(Elem *e, int nwidth); void draw_page(void); void draw_bar(void); void syncinput(void);