notcurses-ncreel: suppert +/- for adding/subbing lines

This commit is contained in:
nick black 2020-07-25 21:53:21 -04:00
parent 55e654d4ab
commit c333c4def5
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

View File

@ -19,6 +19,14 @@ class TabletCtx {
int getLines() const { int getLines() const {
return lines; return lines;
} }
void addLine() {
++lines;
}
void subLine() {
if(lines){
--lines;
}
}
int getIdx() const { int getIdx() const {
return idx; return idx;
} }
@ -122,7 +130,21 @@ int runreels(struct notcurses* nc, struct ncplane* n, ncreel_options* nopts){
case 'd': case 'd':
ncreel_del(nr, ncreel_focused(nr)); ncreel_del(nr, ncreel_focused(nr));
break; break;
case '*': case '+':{
auto t = ncreel_focused(nr);
if(t){
auto tctx = static_cast<TabletCtx*>(nctablet_userptr(t));
tctx->addLine();
}
break;
}case '-':{
auto t = ncreel_focused(nr);
if(t){
auto tctx = static_cast<TabletCtx*>(nctablet_userptr(t));
tctx->subLine();
}
break;
}case '*':
notcurses_debug(nc, stderr); notcurses_debug(nc, stderr);
break; break;
case NCKEY_LEFT: case NCKEY_LEFT:
@ -170,7 +192,7 @@ int main(int argc, char** argv){
} }
int dimy, dimx; int dimy, dimx;
auto nstd = notcurses_stddim_yx(nc, &dimy, &dimx); auto nstd = notcurses_stddim_yx(nc, &dimy, &dimx);
if(ncplane_putstr_aligned(nstd, 0, NCALIGN_CENTER, "(a)dd (d)el (q)uit") <= 0){ if(ncplane_putstr_aligned(nstd, 0, NCALIGN_CENTER, "(a)dd (d)el (+/-) change lines (q)uit") <= 0){
return -1; return -1;
} }
auto n = ncplane_new(nc, dimy - 1 - (margin_t + margin_b), auto n = ncplane_new(nc, dimy - 1 - (margin_t + margin_b),