[tabs] autogrow to the right to next tabstop #1233

pull/2623/head
nick black 2 years ago committed by nick black
parent ceb8cfef0a
commit bec97315ad

@ -1889,15 +1889,17 @@ ncplane_put(ncplane* n, int y, int x, const char* egc, int cols,
// move to the next line. otherwise, simply fill any spaces we can. this has
// already taken place by the time we get here, if it ought have happened.
if(*egc == '\t'){
if(n->x >= n->lenx){
cols = TABSTOP - (n->x % TABSTOP);
if(n->x + 1 >= n->lenx){
if(!n->scrolling && n->autogrow){
// FIXME might need autogrow to the next tab stop out
ncplane_resize_simple(n, n->leny, n->lenx + (cols ? cols - 1 : TABSTOP - 1));
// must refresh targ; resize invalidated it
targ = ncplane_cell_ref_yx(n, n->y, n->x);
}
}
if(cell_load_direct(n, targ, " ", bytes, 1) < 0){
return -1;
}
cols = TABSTOP - (n->x % TABSTOP);
}else{
if(cell_load_direct(n, targ, egc, bytes, cols) < 0){
return -1;

@ -124,6 +124,30 @@ TEST_CASE("TaBs") { // refreshing and delicious
}
}
SUBCASE("GrowWithTaBs") {
struct ncplane_options nopts{};
nopts.rows = 2;
nopts.cols = TABWIDTH;
nopts.flags = NCPLANE_OPTION_AUTOGROW;
auto n = ncplane_create(n_, &nopts);
unsigned y, x;
CHECK(16 == ncplane_putstr(n, "\t\t"));
ncplane_cursor_yx(n, &y, &x);
CHECK(y == 0);
CHECK(x == 16);
CHECK(16 == ncplane_dim_x(n));
CHECK(8 == ncplane_putstr(n, "\t"));
ncplane_cursor_yx(n, &y, &x);
CHECK(x == 24);
CHECK(24 == ncplane_dim_x(n));
for(unsigned i = 0 ; i < ncplane_dim_x(n) ; ++i){
char* c = ncplane_at_yx(n, 0, i, nullptr, nullptr);
REQUIRE(c);
CHECK(0 == strcmp(c, " "));
free(c);
}
}
CHECK(0 == notcurses_stop(nc_));
}

Loading…
Cancel
Save