From 44f80694a3437d121834adf64c38ab36ac7fee5d Mon Sep 17 00:00:00 2001 From: nick black Date: Sat, 1 Feb 2020 14:24:56 -0500 Subject: [PATCH] =?UTF-8?q?selector:=20bind=20with=20=E2=94=B4=20where=20a?= =?UTF-8?q?ppropriate=20#309?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/selector.c | 3 +++ src/poc/selector.c | 38 +++++++++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/lib/selector.c b/src/lib/selector.c index 3afb3fa72..a25d19a8c 100644 --- a/src/lib/selector.c +++ b/src/lib/selector.c @@ -50,6 +50,9 @@ ncselector_draw(ncselector* n){ if(bodywidth < dimx){ ncplane_putegc_yx(n->ncp, 2, dimx - bodywidth, "┬", NULL); } + if((n->titlecols + 4 != dimx) && n->titlecols > n->secondarycols){ + ncplane_putegc_yx(n->ncp, 2, dimx - (n->titlecols + 4), "┴", NULL); + } } // There is always at least one space available on the right for the // secondary title and footer, but we'd prefer to use a few more if we can. diff --git a/src/poc/selector.c b/src/poc/selector.c index 7662ca701..3348b7081 100644 --- a/src/poc/selector.c +++ b/src/poc/selector.c @@ -19,18 +19,29 @@ static struct selector_item items[] = { static void run_selector(struct notcurses* nc, struct ncselector* ns){ + static int item = 0; + ++item; + if(ns == NULL){ + notcurses_stop(nc); + fprintf(stderr, "Error creating selector %d\n", item); + exit(EXIT_FAILURE); + } notcurses_render(nc); char32_t keypress; - while((keypress = notcurses_getc_blocking(nc, NULL)) != (char32_t)-1){ + ncinput ni; + while((keypress = notcurses_getc_blocking(nc, &ni)) != (char32_t)-1){ switch(keypress){ case NCKEY_UP: case 'k': ncselector_previtem(ns, NULL); break; case NCKEY_DOWN: case 'j': ncselector_nextitem(ns, NULL); break; + case NCKEY_ENTER: ncselector_destroy(ns, NULL); return; + case 'M': case 'J': if(ni.ctrl){ ncselector_destroy(ns, NULL); return; } } if(keypress == 'q'){ break; } notcurses_render(nc); } + ncselector_destroy(ns, NULL); } int main(void){ @@ -64,16 +75,29 @@ int main(void){ ncplane_set_fg(notcurses_stdplane(nc), 0x40f040); ncplane_putstr_aligned(notcurses_stdplane(nc), 0, NCALIGN_RIGHT, "selector widget demo"); struct ncselector* ns = ncselector_create(notcurses_stdplane(nc), 3, 0, &sopts); - if(ns == NULL){ - notcurses_stop(nc); - return EXIT_FAILURE; - } run_selector(nc, ns); - ncselector_destroy(ns, NULL); + sopts.title = "short round title"; ns = ncselector_create(notcurses_stdplane(nc), 3, 0, &sopts); run_selector(nc, ns); - ncselector_destroy(ns, NULL); + + sopts.title = "short round title"; + sopts.secondary = "now this secondary is also very, very, very outlandishly long, you see"; + ns = ncselector_create(notcurses_stdplane(nc), 3, 0, &sopts); + run_selector(nc, ns); + + sopts.title = "the whole world is watching"; + sopts.secondary = NULL; + sopts.footer = "now this FOOTERFOOTER is also very, very, very outlandishly long, you see"; + ns = ncselector_create(notcurses_stdplane(nc), 3, 0, &sopts); + run_selector(nc, ns); + + sopts.title = "chomps"; + sopts.secondary = NULL; + sopts.footer = NULL; + ns = ncselector_create(notcurses_stdplane(nc), 3, 0, &sopts); + run_selector(nc, ns); + if(notcurses_stop(nc)){ return EXIT_FAILURE; }