mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-18 03:25:55 +00:00
ncplane_puttext: another test, another bug #691
This commit is contained in:
parent
d1f8b9237d
commit
97517d0473
@ -1510,6 +1510,7 @@ int ncplane_puttext(ncplane* n, int y, ncalign_e align, const char* text, size_t
|
|||||||
// might catch a space, in which case we want breaker updated. if it's
|
// might catch a space, in which case we want breaker updated. if it's
|
||||||
// not a space, it won't be printed, and we carry the word forward.
|
// not a space, it won't be printed, and we carry the word forward.
|
||||||
// FIXME what ought be done with \n or multiple spaces?
|
// FIXME what ought be done with \n or multiple spaces?
|
||||||
|
//fprintf(stderr, "laying out [%s] at %d (%d)\n", linestart, x, dimx);
|
||||||
while(*text && x <= dimx){
|
while(*text && x <= dimx){
|
||||||
wchar_t w;
|
wchar_t w;
|
||||||
size_t consumed = mbrtowc(&w, text, MB_CUR_MAX, &mbstate);
|
size_t consumed = mbrtowc(&w, text, MB_CUR_MAX, &mbstate);
|
||||||
@ -1538,17 +1539,17 @@ int ncplane_puttext(ncplane* n, int y, ncalign_e align, const char* text, size_t
|
|||||||
x += width;
|
x += width;
|
||||||
text += consumed;
|
text += consumed;
|
||||||
}
|
}
|
||||||
int carrycols = 0;
|
//fprintf(stderr, "exited at %d (%d) looking at %.*s\n", x, dimx, breaker - linestart, linestart);
|
||||||
if(x > dimx){
|
// if we have no breaker, we got a word that was longer than our line;
|
||||||
// the last character was one past the amount we can print.
|
// print what we can and move along. if *text is nul, we're done.
|
||||||
// set carrycols to the amount since breaker.
|
|
||||||
carrycols = text - breaker;
|
|
||||||
}
|
|
||||||
totalcols += (breaker - linestart);
|
|
||||||
const int xpos = ncplane_align(n, align, x);
|
|
||||||
if(!*text || breaker == NULL){
|
if(!*text || breaker == NULL){
|
||||||
breaker = text;
|
breaker = text;
|
||||||
}
|
}
|
||||||
|
int carrycols = 0;
|
||||||
|
carrycols = text - breaker;
|
||||||
|
if(breaker != linestart){
|
||||||
|
totalcols += (breaker - linestart);
|
||||||
|
const int xpos = ncplane_align(n, align, x);
|
||||||
// blows out if we supply a y beyond leny
|
// blows out if we supply a y beyond leny
|
||||||
if(ncplane_putnstr_yx(n, y, xpos, breaker - linestart, linestart) < 0){
|
if(ncplane_putnstr_yx(n, y, xpos, breaker - linestart, linestart) < 0){
|
||||||
if(bytes){
|
if(bytes){
|
||||||
@ -1556,9 +1557,10 @@ int ncplane_puttext(ncplane* n, int y, ncalign_e align, const char* text, size_t
|
|||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
x = carrycols;
|
x = carrycols;
|
||||||
linestart = breaker + 1;
|
linestart = breaker + 1;
|
||||||
++y; // FIXME scrolling!
|
++y; // FIXME scrolling!??!!
|
||||||
}while(*text);
|
}while(*text);
|
||||||
if(bytes){
|
if(bytes){
|
||||||
*bytes = text - beginning;
|
*bytes = text - beginning;
|
||||||
|
@ -85,6 +85,30 @@ TEST_CASE("TextLayout") {
|
|||||||
ncplane_destroy(sp);
|
ncplane_destroy(sp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// lay out text where a word crosses the boundary
|
||||||
|
SUBCASE("LayoutCrossBoundary") {
|
||||||
|
auto sp = ncplane_new(nc_, 3, 10, 0, 0, nullptr);
|
||||||
|
REQUIRE(sp);
|
||||||
|
size_t bytes;
|
||||||
|
const char boundstr[] = "my grasping arms";
|
||||||
|
CHECK(0 < ncplane_puttext(sp, 0, NCALIGN_CENTER, boundstr, &bytes));
|
||||||
|
CHECK(0 == notcurses_render(nc_));
|
||||||
|
CHECK(bytes == strlen(boundstr));
|
||||||
|
char* line = ncplane_contents(sp, 0, 0, 1, 10);
|
||||||
|
REQUIRE(line);
|
||||||
|
CHECK(0 == strcmp(line, "my"));
|
||||||
|
free(line);
|
||||||
|
line = ncplane_contents(sp, 1, 0, 1, 10);
|
||||||
|
REQUIRE(line);
|
||||||
|
CHECK(0 == strcmp(line, "grasping"));
|
||||||
|
free(line);
|
||||||
|
line = ncplane_contents(sp, 2, 0, 1, 10);
|
||||||
|
REQUIRE(line);
|
||||||
|
CHECK(0 == strcmp(line, "arms"));
|
||||||
|
free(line);
|
||||||
|
ncplane_destroy(sp);
|
||||||
|
}
|
||||||
|
|
||||||
CHECK(0 == notcurses_stop(nc_));
|
CHECK(0 == notcurses_stop(nc_));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user