From 5a205b8410f0e9f8b0e3711f64d2c81a6ab2db5a Mon Sep 17 00:00:00 2001 From: nick black Date: Tue, 14 Dec 2021 22:24:45 -0500 Subject: [PATCH] [tfman] toggle visibility of structure menu with 's' #2457 --- CMakeLists.txt | 5 ++--- src/man/main.c | 4 +++- src/man/structure.c | 14 ++++++++++++++ src/man/structure.h | 2 ++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c6c929791..9970a9e21 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -738,9 +738,8 @@ target_link_libraries(ncplayer ) endif() endif() -else() - # No binaries built - set(MANSOURCE1 "") +else() +set(MANSOURCE1 "") # no executables were built endif() # BUILD_EXECUTABLES ############################################################################ diff --git a/src/man/main.c b/src/man/main.c index 8ad9e4aca..67ebd79e9 100644 --- a/src/man/main.c +++ b/src/man/main.c @@ -750,6 +750,7 @@ draw_domnode(struct ncplane* p, const pagedom* dom, const pagenode* n, case LINE_IP: // indented paragraph if(*wrotetext){ if(n->text){ + ncplane_set_fg_rgb(p, 0xe0f0ff); ncplane_puttext(p, -1, NCALIGN_LEFT, "\n\n", &b); putpara(p, n->text); } @@ -822,6 +823,7 @@ render_troff(struct notcurses* nc, const unsigned char* map, size_t mlen, if(pman == NULL){ return NULL; } + ncplane_set_base(pman, " ", 0, 0); if(draw_content(stdn, pman)){ ncplane_destroy(pman); return NULL; @@ -958,7 +960,7 @@ manloop(struct notcurses* nc, const char* arg){ } break; case 's': - // FIXME toggle structure browser visibility + docstructure_toggle(page, bar, dom.ds); break; case NCKEY_TAB: case L'\u21c6': // FIXME switch between browsers diff --git a/src/man/structure.c b/src/man/structure.c index cb01061aa..1156c9191 100644 --- a/src/man/structure.c +++ b/src/man/structure.c @@ -14,6 +14,7 @@ typedef struct docstructure { struct nctree* nct; // one entry for each hierarchy level + terminator unsigned curpath[HIERARCHY_MAX + 1]; + bool visible; } docstructure; static int @@ -60,9 +61,22 @@ docstructure* docstructure_create(struct ncplane* n){ for(unsigned z = 0 ; z < sizeof(ds->curpath) / sizeof(*ds->curpath) ; ++z){ ds->curpath[z] = UINT_MAX; } + ds->visible = true; return ds; } +// to show the structure menu, it ought be on top. otherwise, the page plane +// ought be below the bar, which ought be on top. +void docstructure_toggle(struct ncplane* p, struct ncplane* b, docstructure* ds){ + if(!(ds->visible = !ds->visible)){ + ncplane_move_top(p); + ncplane_move_top(b); + }else{ + ncplane_move_bottom(p); + ncplane_move_bottom(notcurses_stdplane(ncplane_notcurses(p))); + } +} + void docstructure_free(docstructure* ds){ if(ds){ nctree_destroy(ds->nct); diff --git a/src/man/structure.h b/src/man/structure.h index 83a15eb80..b1ff2819c 100644 --- a/src/man/structure.h +++ b/src/man/structure.h @@ -17,6 +17,8 @@ typedef enum { struct docstructure* docstructure_create(struct ncplane* n); void docstructure_free(struct docstructure* ds); +void docstructure_toggle(struct ncplane* p, struct ncplane* b, struct docstructure *ds); + // add the specified [sub]section to the document strucure. |line| refers to // the row on the display plane, *not* the line in the original content. int docstructure_add(struct docstructure* ds, const char* title, int line,