reader PoC: accept -hs for horizontal scrolling #839

This commit is contained in:
nick black 2020-08-25 08:26:07 -04:00
parent 7cbb2e9110
commit afc06a0271
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
2 changed files with 28 additions and 5 deletions

View File

@ -89,10 +89,10 @@ int ncreader_move_left(ncreader* n){
if(y == 0){
return -1; // no move possible
}
viewx = n->textarea->lenx - 1; // FIXME find end of particular row
viewx = n->ncp->lenx - 1; // FIXME find end of particular row
--y;
textx = viewx;
n->xproject = 0;
textx = n->textarea->x - 1;
n->xproject = n->textarea->x - n->ncp->x;
}else{
// if we're on the first column of the viewarea, but not the first column
// of the textarea, we must be able to scroll to the left. do so.

View File

@ -7,11 +7,26 @@
using namespace ncpp;
auto main() -> int {
auto usage(const char* argv0, int ret) -> void {
std::cerr << "usage: " << argv0 << " [ -hs ]" << std::endl;
exit(ret);
}
auto main(int argc, const char** argv) -> int {
if(!setlocale(LC_ALL, "")){
std::cout << "Error setting locale\n";
return EXIT_FAILURE;
}
bool horscroll = false;
if(argc == 2){
if(strcmp(argv[1], "-hs") == 0){
horscroll = true;
}else{
usage(argv[0], EXIT_FAILURE);
}
}else if(argc > 2){
usage(argv[0], EXIT_FAILURE);
}
notcurses_options nopts{};
nopts.flags = NCOPTION_INHIBIT_SETLOCALE;
NotCurses nc(nopts);
@ -22,6 +37,7 @@ auto main() -> int {
opts.physrows = dimy / 8;
opts.physcols = dimx / 2;
opts.egc = "";
opts.flags = horscroll ? NCREADER_OPTION_HORSCROLL : 0;
// FIXME c++ is crashing
//Reader nr(nc, 0, 0, &opts);
auto nr = ncreader_create(**n, 2, 2, &opts);
@ -38,8 +54,15 @@ auto main() -> int {
break;
}
int y, x;
ncplane_cursor_yx(ncreader_plane(nr), &y, &x);
struct ncplane* ncp = ncreader_plane(nr);
ncplane_cursor_yx(ncp, &y, &x);
nc.cursor_enable(y + 2, x + 2);
int ncpy, ncpx;
ncplane_cursor_yx(ncp, &ncpy, &ncpx);
int tgeomy, tgeomx, vgeomy, vgeomx;
(*n)->get_dim(&tgeomy, &tgeomx);
ncplane_dim_yx(ncp, &vgeomy, &vgeomx);
(*n)->printf(0, 0, "Cursor: %d/%d Viewgeom: %d/%d Textgeom: %d/%d", ncpy, ncpx, vgeomy, vgeomx, tgeomy, tgeomx);
nc.render();
}
nc.render();