From ff0cffc590193b43e202858ae233219cd00587e1 Mon Sep 17 00:00:00 2001 From: MasFlam Date: Tue, 13 Jul 2021 19:29:41 +0200 Subject: [PATCH] Spice up the tabbed poc --- src/poc/tabbed.c | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/poc/tabbed.c b/src/poc/tabbed.c index fa3f67ae8..3741f3ede 100644 --- a/src/poc/tabbed.c +++ b/src/poc/tabbed.c @@ -9,17 +9,17 @@ notcurses_getc_blocking(nc, NULL); \ }while(0) +static const char *tabnames[] = { + "apple", "banana", "cheese", "dumplings", "eggs", "fried eggs", "gingerbread", + "hummus", "ice cream", "jelly", "kiwi", "lamb", "milk", "noodles", "orange", + "pierogi", "quiche", "ramen", "steak", "truffle", "urchins", "venison", + "waffles", "xouba", "yolk", "zucchini" +}; + void tabcbfn(struct nctab* t, struct ncplane* ncp, void* curry){ (void) t; (void) curry; ncplane_erase(ncp); - ncplane_puttext(ncp, -1, NCALIGN_LEFT, - "Use left/right arrow keys for navigation, " - "'[' and ']' to rotate tabs, " - "'a' to add a tab, 'r' to remove a tab, " - "',' and '.' to move the selected tab, " - "and 'q' to quit", - NULL); } void print_usage(char** argv){ @@ -83,19 +83,24 @@ int main(int argc, char** argv){ struct nctab* t_; // stupid unused result warnings (void) t_; ncplane_set_base(nctabbed_content_plane(nct), " ", 0, NCCHANNELS_INITIALIZER(255, 255, 255, 15, 60, 15)); - REDRAW(); t_ = nctabbed_add(nct, NULL, NULL, tabcbfn, "Tab #1", NULL); - REDRAW(); - t_ = nctabbed_add(nct, NULL, NULL, tabcbfn, "Tab #2", NULL); - REDRAW(); - t_ = nctabbed_add(nct, NULL, NULL, tabcbfn, "Tab #3", NULL); - REDRAW(); - t_ = nctabbed_add(nct, NULL, NULL, tabcbfn, "alpha", NULL); - REDRAW(); - t_ = nctabbed_add(nct, NULL, NULL, tabcbfn, "beta", NULL); - REDRAW(); t_ = nctabbed_add(nct, NULL, NULL, tabcbfn, "gamma", NULL); - REDRAW(); + t_ = nctabbed_add(nct, NULL, NULL, tabcbfn, "beta", NULL); + t_ = nctabbed_add(nct, NULL, NULL, tabcbfn, "alpha", NULL); + t_ = nctabbed_add(nct, NULL, NULL, tabcbfn, "Tab #3", NULL); + t_ = nctabbed_add(nct, NULL, NULL, tabcbfn, "Tab #2", NULL); + ncplane_puttext(stdp, 1, NCALIGN_CENTER, + "Use left/right arrow keys for navigation, " + "'[' and ']' to rotate tabs, " + "'a' to add a tab, 'r' to remove a tab, " + "',' and '.' to move the selected tab, " + "and 'q' to quit", + NULL); + nctabbed_redraw(nct); + if(notcurses_render(nc) < 0){ + goto ded; + } + int tabnameind = 0; uint32_t c; while((c = notcurses_getc_blocking(nc, NULL)) != 'q'){ switch(c){ @@ -118,7 +123,8 @@ int main(int argc, char** argv){ nctab_move_right(nct, nctabbed_selected(nct)); break; case 'a': - t_ = nctabbed_add(nct, NULL, NULL, tabcbfn, "added tab", NULL); + t_ = nctabbed_add(nct, NULL, NULL, tabcbfn, tabnames[tabnameind++], NULL); + tabnameind %= sizeof(tabnames) / sizeof(tabnames[0]); break; case 'r': nctabbed_del(nct, nctabbed_selected(nct));