[tfman] simplify main loop

This commit is contained in:
nick black 2021-12-16 18:29:17 -05:00 committed by nick black
parent 3c17bc78e2
commit dca02e6aae
2 changed files with 22 additions and 35 deletions

View File

@ -82,8 +82,8 @@ Why use this non-standard library?
and transparent regions. All APIs natively support 24-bit color, quantized
down as necessary for the terminal.
* Portable support for bitmapped graphics, whether using Sixel, Kitty, the iTerm2
protocol, or even the Linux framebuffer console.
* Portable support for bitmapped graphics, using Sixel, Kitty,
and even the Linux framebuffer console.
* Support for unambiguous [keyboard protocols](https://sw.kovidgoyal.net/kitty/keyboard-protocol/).

View File

@ -555,7 +555,8 @@ manloop(struct notcurses* nc, const char* arg, unsigned noui){
}
uint32_t key;
do{
int newy;
bool movedown = false;
int newy = ncplane_y(page);
ncinput ni;
key = notcurses_get(nc, NULL, &ni);
if(ni.evtype == NCTYPE_RELEASE){
@ -571,57 +572,43 @@ manloop(struct notcurses* nc, const char* arg, unsigned noui){
docstructure_toggle(page, bar, dom.ds);
break;
case 'h': case NCKEY_LEFT:
if((newy = docstructure_prev(dom.ds)) > 1){
newy = 1;
}
ncplane_move_yx(page, newy, 0);
docstructure_move(dom.ds, newy, false);
newy = docstructure_prev(dom.ds);
break;
case 'l': case NCKEY_RIGHT:
newy = docstructure_next(dom.ds);
if(newy + (int)ncplane_dim_y(page) < (int)ncplane_dim_y(stdn)){
newy += (int)ncplane_dim_y(stdn) - (newy + (int)ncplane_dim_y(page)) - 1;
}
ncplane_move_yx(page, newy, 0);
docstructure_move(dom.ds, newy, true);
movedown = true;
break;
case 'k': case NCKEY_UP:
if(ncplane_y(page) < 1){
ncplane_move_rel(page, 1, 0);
}
newy = ncplane_y(page);
docstructure_move(dom.ds, newy, false);
newy = ncplane_y(page) + 1;
break;
// we can move down iff our last line is beyond the visible area
case 'j': case NCKEY_DOWN:
if(ncplane_y(page) + ncplane_dim_y(page) >= ncplane_dim_y(stdn)){
ncplane_move_rel(page, -1, 0);
}
newy = ncplane_y(page);
docstructure_move(dom.ds, newy, true);
newy = ncplane_y(page) - 1;
movedown = true;
break;
case 'b': case NCKEY_PGUP:{
newy = ncplane_y(page) + (int)ncplane_dim_y(stdn);
if(newy > 1){
newy = 1;
}
ncplane_move_yx(page, newy, 0);
docstructure_move(dom.ds, newy, false);
break;
}case 'f': case NCKEY_PGDOWN:{
newy = ncplane_y(page) - (int)ncplane_dim_y(stdn) + 1;
if(newy + (int)ncplane_dim_y(page) < (int)ncplane_dim_y(stdn)){
newy += (int)ncplane_dim_y(stdn) - (newy + (int)ncplane_dim_y(page)) - 1;
}
ncplane_move_yx(page, newy, 0);
docstructure_move(dom.ds, newy, true);
movedown = true;
break;
}case 'q':
ret = 0;
goto done;
}
if(notcurses_render(nc)){
goto done;
if(newy > 1){
newy = 1;
}
if(newy + (int)ncplane_dim_y(page) < (int)ncplane_dim_y(stdn)){
newy += (int)ncplane_dim_y(stdn) - (newy + (int)ncplane_dim_y(page)) - 1;
}
if(newy != ncplane_y(page)){
ncplane_move_yx(page, newy, 0);
docstructure_move(dom.ds, newy, movedown);
if(notcurses_render(nc)){
goto done;
}
}
}while(key != (uint32_t)-1);