ncplane_puttext(): allow NULL for sbytes

This commit is contained in:
nick black 2020-06-14 21:06:24 -04:00
parent 472b6a3f54
commit 3f114f4305
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
2 changed files with 15 additions and 4 deletions

View File

@ -1,6 +1,9 @@
This document attempts to list user-visible changes and any major internal
rearrangements of Notcurses.
* 1.5.2 (not yet released)
* A `NULL` value can now be passed as `sbytes` to `ncplane_puttext()`.
* 1.5.1 (2020-07-15)
* The semantics of rendering have changed slightly. In 1.5.0 and prior
versions, a cell without a glyph was replaced *in toto* by that plane's

View File

@ -1507,13 +1507,17 @@ int ncplane_puttext(ncplane* n, int y, ncalign_e align, const char* text, size_t
size_t consumed = mbrtowc(&w, text, MB_CUR_MAX, &mbstate);
if(consumed == (size_t)-2 || consumed == (size_t)-1){
logerror(n->nc, "Invalid UTF-8 after %zu bytes\n", text - beginning);
*bytes = text - beginning;
if(bytes){
*bytes = text - beginning;
}
return -1;
}
width = wcwidth(w);
if(width < 0){
logerror(n->nc, "Non-printable UTF-8 after %zu bytes\n", text - beginning);
*bytes = text - beginning;
if(bytes){
*bytes = text - beginning;
}
return -1;
}
if(x + width >= dimx){
@ -1539,14 +1543,18 @@ int ncplane_puttext(ncplane* n, int y, ncalign_e align, const char* text, size_t
breaker = text;
}
if(ncplane_putnstr_yx(n, y, xpos, breaker - linestart, linestart) < 0){
*bytes = linestart - beginning;
if(bytes){
*bytes = linestart - beginning;
}
return -1;
}
x = carrycols;
linestart = breaker + 1;
++y; // FIXME scrolling!
}while(*text);
*bytes = text - beginning;
if(bytes){
*bytes = text - beginning;
}
return totalcols;
}