|
|
@ -1671,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.
|
|
|
|
// 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?
|
|
|
|
while(*text && x <= dimx){
|
|
|
|
while(*text && x <= dimx){
|
|
|
|
//fprintf(stderr, "laying out [%s] at %d (%d)\n", linestart, x, dimx);
|
|
|
|
fprintf(stderr, "laying out [%s] at %d <= %d, %zu\n", linestart, x, dimx, text - linestart);
|
|
|
|
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);
|
|
|
|
if(consumed == (size_t)-2 || consumed == (size_t)-1){
|
|
|
|
if(consumed == (size_t)-2 || consumed == (size_t)-1){
|
|
|
@ -1692,7 +1692,7 @@ int ncplane_puttext(ncplane* n, int y, ncalign_e align, const char* text, size_t
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
width = wcwidth(w);
|
|
|
|
width = wcwidth(w);
|
|
|
|
//fprintf(stderr, "have non-wordbreak char %lc (%d)\n", w, width);
|
|
|
|
fprintf(stderr, "have char %lc (%d)\n", w, width);
|
|
|
|
if(width < 0){
|
|
|
|
if(width < 0){
|
|
|
|
width = 0;
|
|
|
|
width = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1702,8 +1702,8 @@ int ncplane_puttext(ncplane* n, int y, ncalign_e align, const char* text, size_t
|
|
|
|
x += width;
|
|
|
|
x += width;
|
|
|
|
text += consumed;
|
|
|
|
text += consumed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//fprintf(stderr, "OUT! %s %zu\n", linestart, text - linestart);
|
|
|
|
fprintf(stderr, "OUT! %s %zu\n", linestart, text - linestart);
|
|
|
|
int carrycols = 0;
|
|
|
|
int carrybytes = 0;
|
|
|
|
bool overlong = false; // ugh
|
|
|
|
bool overlong = false; // ugh
|
|
|
|
// if we have no breaker, we got a single word that was longer than our
|
|
|
|
// 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.
|
|
|
|
// line. print what we can and move along. if *text is nul, we're done.
|
|
|
@ -1716,17 +1716,17 @@ int ncplane_puttext(ncplane* n, int y, ncalign_e align, const char* text, size_t
|
|
|
|
if(overlong_word(breaker + 1, dimx)){
|
|
|
|
if(overlong_word(breaker + 1, dimx)){
|
|
|
|
breaker = text;
|
|
|
|
breaker = text;
|
|
|
|
overlong = true;
|
|
|
|
overlong = true;
|
|
|
|
//fprintf(stderr, "NEW BREAKER: %s\n", breaker);
|
|
|
|
fprintf(stderr, "NEW BREAKER: %s\n", breaker);
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
carrycols = text - breaker;
|
|
|
|
carrybytes = 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){
|
|
|
|
if(breaker != linestart){
|
|
|
|
totalcols += x;
|
|
|
|
totalcols += x;
|
|
|
|
const int xpos = ncplane_align(n, align, x);
|
|
|
|
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
|
|
|
|
//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(ncplane_putnstr_yx(n, y, xpos, breaker - linestart, linestart) <= 0){
|
|
|
|
if(bytes){
|
|
|
|
if(bytes){
|
|
|
|
*bytes = linestart - beginning;
|
|
|
|
*bytes = linestart - beginning;
|
|
|
@ -1734,7 +1734,7 @@ int ncplane_puttext(ncplane* n, int y, ncalign_e align, const char* text, size_t
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
x = carrycols;
|
|
|
|
x = carrybytes;
|
|
|
|
if(breaker == text || overlong){
|
|
|
|
if(breaker == text || overlong){
|
|
|
|
linestart = breaker;
|
|
|
|
linestart = breaker;
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
@ -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 ncplane_putnstr_yx(struct ncplane* n, int y, int x, size_t s, const char* gclusters){
|
|
|
|
int ret = 0;
|
|
|
|
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
|
|
|
|
// FIXME speed up this blissfully naive solution
|
|
|
|
while((size_t)ret < s && *gclusters){
|
|
|
|
while((size_t)ret < s && *gclusters){
|
|
|
|
int wcs;
|
|
|
|
int wcs;
|
|
|
|