|
|
|
@ -1657,7 +1657,6 @@ int ncplane_puttext(ncplane* n, int y, ncalign_e align, const char* text, size_t
|
|
|
|
|
// how much space we have available, and begin iterating from text. remember
|
|
|
|
|
// the most recent linebreaker that we see. when we exhaust our line, print
|
|
|
|
|
// through the linebreaker, and advance text.
|
|
|
|
|
// FIXME what about a long word? do we want to leave the big gap?
|
|
|
|
|
const int dimx = ncplane_dim_x(n);
|
|
|
|
|
const int dimy = ncplane_dim_y(n);
|
|
|
|
|
const char* linestart = text;
|
|
|
|
@ -1672,7 +1671,7 @@ int ncplane_puttext(ncplane* n, int y, ncalign_e align, const char* text, size_t
|
|
|
|
|
// not a space, it won't be printed, and we carry the word forward.
|
|
|
|
|
// FIXME what ought be done with \n or multiple spaces?
|
|
|
|
|
while(*text && x <= dimx){
|
|
|
|
|
fprintf(stderr, "laying out [%s] at %d (%d)\n", linestart, x, dimx);
|
|
|
|
|
//fprintf(stderr, "laying out [%s] at %d (%d)\n", linestart, x, dimx);
|
|
|
|
|
wchar_t w;
|
|
|
|
|
size_t consumed = mbrtowc(&w, text, MB_CUR_MAX, &mbstate);
|
|
|
|
|
if(consumed == (size_t)-2 || consumed == (size_t)-1){
|
|
|
|
@ -1703,30 +1702,31 @@ fprintf(stderr, "laying out [%s] at %d (%d)\n", linestart, x, dimx);
|
|
|
|
|
x += width;
|
|
|
|
|
text += consumed;
|
|
|
|
|
}
|
|
|
|
|
fprintf(stderr, "OUT! %s\n", linestart);
|
|
|
|
|
//fprintf(stderr, "OUT! %s %zu\n", linestart, text - linestart);
|
|
|
|
|
int carrycols = 0;
|
|
|
|
|
bool overlong = false; // ugh
|
|
|
|
|
// if we have no breaker, we got a word that was longer than our line;
|
|
|
|
|
// print what we can and move along. if *text is nul, we're done.
|
|
|
|
|
// if we have no breaker, we got a single word that was longer than our
|
|
|
|
|
// line. print what we can and move along. if *text is nul, we're done.
|
|
|
|
|
if(!*text || breaker == NULL){
|
|
|
|
|
breaker = text + 1;
|
|
|
|
|
breaker = text/* + 1*/;
|
|
|
|
|
}else{
|
|
|
|
|
// if the word on which we ended is overlong (longer than the plane is
|
|
|
|
|
// wide), go ahead and start printing it where it starts
|
|
|
|
|
// wide), go ahead and start printing it where it starts. otherwise, punt
|
|
|
|
|
// it to the next line, to avoid breaking it across lines.
|
|
|
|
|
if(overlong_word(breaker + 1, dimx)){
|
|
|
|
|
breaker = text;
|
|
|
|
|
overlong = true;
|
|
|
|
|
fprintf(stderr, "NEW BREAKER: %s\n", breaker);
|
|
|
|
|
//fprintf(stderr, "NEW BREAKER: %s\n", breaker);
|
|
|
|
|
}else{
|
|
|
|
|
carrycols = text - breaker;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fprintf(stderr, "exited at %d (%d) %zu looking at [%.*s]\n", x, dimx, breaker - linestart, (int)(breaker - linestart), linestart);
|
|
|
|
|
//fprintf(stderr, "exited at %d (%d) %zu looking at [%.*s]\n", x, dimx, breaker - linestart, (int)(breaker - linestart), linestart);
|
|
|
|
|
if(breaker != linestart){
|
|
|
|
|
totalcols += (breaker - linestart);
|
|
|
|
|
totalcols += x;
|
|
|
|
|
const int xpos = ncplane_align(n, align, x);
|
|
|
|
|
// blows out if we supply a y beyond leny
|
|
|
|
|
fprintf(stderr, "y: %d %ld %.*s\n", y, breaker - linestart, (int)(breaker - linestart), linestart);
|
|
|
|
|
//fprintf(stderr, "y: %d %ld %.*s\n", y, breaker - linestart, (int)(breaker - linestart), linestart);
|
|
|
|
|
if(ncplane_putnstr_yx(n, y, xpos, breaker - linestart, linestart) <= 0){
|
|
|
|
|
if(bytes){
|
|
|
|
|
*bytes = linestart - beginning;
|
|
|
|
@ -1735,7 +1735,7 @@ fprintf(stderr, "y: %d %ld %.*s\n", y, breaker - linestart, (int)(breaker - line
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
x = carrycols;
|
|
|
|
|
if(breaker == text + 1 || overlong){
|
|
|
|
|
if(breaker == text || overlong){
|
|
|
|
|
linestart = breaker;
|
|
|
|
|
}else{
|
|
|
|
|
linestart = breaker + 1;
|
|
|
|
@ -2458,7 +2458,7 @@ int ncplane_putnstr_aligned(struct ncplane* n, int y, ncalign_e align, size_t s,
|
|
|
|
|
|
|
|
|
|
int ncplane_putnstr_yx(struct ncplane* n, int y, int x, size_t s, const char* gclusters){
|
|
|
|
|
int ret = 0;
|
|
|
|
|
fprintf(stderr, "PUT %zu at %d/%d [%.*s]\n", s, y, x, (int)s, gclusters);
|
|
|
|
|
//fprintf(stderr, "PUT %zu at %d/%d [%.*s]\n", s, y, x, (int)s, gclusters);
|
|
|
|
|
// FIXME speed up this blissfully naive solution
|
|
|
|
|
while((size_t)ret < s && *gclusters){
|
|
|
|
|
int wcs;
|
|
|
|
|