From 25baa10f7289e245a5ab4071d0823988a6d52965 Mon Sep 17 00:00:00 2001 From: nick black Date: Mon, 11 May 2020 04:22:44 -0400 Subject: [PATCH] special-case double/rounded boxes in ASCII #325 --- include/notcurses/notcurses.h | 16 ++++++---------- src/lib/notcurses.c | 21 +++++++++++++++++++++ src/lib/selector.c | 9 ++++----- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index 0bb33d3a9..339d3f58e 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -2008,11 +2008,9 @@ cells_load_box(struct ncplane* n, uint32_t attrs, uint64_t channels, return -1; } -static inline int -cells_rounded_box(struct ncplane* n, uint32_t attr, uint64_t channels, - cell* ul, cell* ur, cell* ll, cell* lr, cell* hl, cell* vl){ - return cells_load_box(n, attr, channels, ul, ur, ll, lr, hl, vl, "╭╮╰╯─│"); -} +API int cells_rounded_box(struct ncplane* n, uint32_t attr, uint64_t channels, + cell* ul, cell* ur, cell* ll, cell* lr, + cell* hl, cell* vl); static inline int ncplane_rounded_box(struct ncplane* n, uint32_t attr, uint64_t channels, @@ -2039,11 +2037,9 @@ ncplane_rounded_box_sized(struct ncplane* n, uint32_t attr, uint64_t channels, x + xlen - 1, ctlword); } -static inline int -cells_double_box(struct ncplane* n, uint32_t attr, uint64_t channels, - cell* ul, cell* ur, cell* ll, cell* lr, cell* hl, cell* vl){ - return cells_load_box(n, attr, channels, ul, ur, ll, lr, hl, vl, "╔╗╚╝═║"); -} +API int cells_double_box(struct ncplane* n, uint32_t attr, uint64_t channels, + cell* ul, cell* ur, cell* ll, cell* lr, + cell* hl, cell* vl); static inline int ncplane_double_box(struct ncplane* n, uint32_t attr, uint64_t channels, diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index f9966b843..2ed88ec3b 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -2122,3 +2122,24 @@ char* ncplane_contents(const ncplane* nc, int begy, int begx, int leny, int lenx } return ret; } + +int cells_ascii_box(struct ncplane* n, uint32_t attr, uint64_t channels, + cell* ul, cell* ur, cell* ll, cell* lr, cell* hl, cell* vl){ + return cells_load_box(n, attr, channels, ul, ur, ll, lr, hl, vl, "/\\\\/-|"); +} + +int cells_double_box(struct ncplane* n, uint32_t attr, uint64_t channels, + cell* ul, cell* ur, cell* ll, cell* lr, cell* hl, cell* vl){ + if(enforce_utf8(n->nc)){ + return cells_load_box(n, attr, channels, ul, ur, ll, lr, hl, vl, "╔╗╚╝═║"); + } + return cells_ascii_box(n, attr, channels, ul, ur, ll, lr, hl, vl); +} + +int cells_rounded_box(struct ncplane* n, uint32_t attr, uint64_t channels, + cell* ul, cell* ur, cell* ll, cell* lr, cell* hl, cell* vl){ + if(enforce_utf8(n->nc)){ + return cells_load_box(n, attr, channels, ul, ur, ll, lr, hl, vl, "╭╮╰╯─│"); + } + return cells_ascii_box(n, attr, channels, ul, ur, ll, lr, hl, vl); +} diff --git a/src/lib/selector.c b/src/lib/selector.c index 2029a2a7e..2ad226f6d 100644 --- a/src/lib/selector.c +++ b/src/lib/selector.c @@ -495,12 +495,11 @@ ncmultiselector_draw(ncmultiselector* n){ if(printidx == n->current){ n->ncp->channels = (uint64_t)channels_bchannel(n->descchannels) << 32u | channels_fchannel(n->descchannels); } - // FIXME this is the wrong place to do this. see https://github.com/dankamongmen/notcurses/issues/451 -if(enforce_utf8(n->ncp->nc)){ + if(enforce_utf8(n->ncp->nc)){ ncplane_putegc_yx(n->ncp, yoff, bodyoffset, n->items[printidx].selected ? "☒" : "☐", NULL); -}else{ - ncplane_putsimple_yx(n->ncp, yoff, bodyoffset, n->items[printidx].selected ? 'X' : '-'); -} + }else{ + ncplane_putsimple_yx(n->ncp, yoff, bodyoffset, n->items[printidx].selected ? 'X' : '-'); + } n->ncp->channels = n->opchannels; if(printidx == n->current){ n->ncp->channels = (uint64_t)channels_bchannel(n->opchannels) << 32u | channels_fchannel(n->opchannels);