Skip to content

Commit

Permalink
[blitcore] accept newlines, set colcount = 1 #2196
Browse files Browse the repository at this point in the history
  • Loading branch information
dankamongmen committed Nov 24, 2021
1 parent 700a659 commit 2e5486a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 26 deletions.
1 change: 1 addition & 0 deletions src/lib/egcpool.h
Expand Up @@ -122,6 +122,7 @@ utf8_egc_len(const char* gcluster, int* colcount){
if(cols < 0){
injoin = false;
if(iswspace(wc)){ // newline or tab
*colcount = 1;
return ret + 1;
}
cols = 1;
Expand Down
39 changes: 17 additions & 22 deletions src/lib/notcurses.c
Expand Up @@ -1279,16 +1279,10 @@ int notcurses_stop(notcurses* nc){
if(nc){
ret |= notcurses_stop_minimal(nc);
// if we were not using the alternate screen, our cursor's wherever we last
// wrote. move it to the bottom left of the screen, *unless*
// PRESERVE_CURSOR was used, which is a bit more complex.
if((nc->flags & NCOPTION_PRESERVE_CURSOR) || !get_escape(&nc->tcache, ESCAPE_SMCUP)){
unsigned targy = nc->rstate.logendy;
// wrote. move it to the furthest place to which it advanced.
if(!get_escape(&nc->tcache, ESCAPE_SMCUP)){
fbuf_reset(&nc->rstate.f);
if(++targy >= nc->lfdimy){
fbuf_putc(&nc->rstate.f, '\n');
--targy;
}
goto_location(nc, &nc->rstate.f, targy, 0, NULL);
goto_location(nc, &nc->rstate.f, nc->rstate.logendy, nc->rstate.logendx, NULL);
fbuf_finalize(&nc->rstate.f, stdout);
}
if(nc->stdplane){
Expand Down Expand Up @@ -1668,7 +1662,7 @@ int cell_load(ncplane* n, nccell* c, const char* gcluster){
// either or both of |y|/|x| is -1, the current cursor location for that
// dimension will be used. if the glyph cannot fit on the current line, it is
// an error unless scrolling is enabled.
static inline int
static int
ncplane_put(ncplane* n, int y, int x, const char* egc, int cols,
uint16_t stylemask, uint64_t channels, int bytes){
if(n->sprite){
Expand Down Expand Up @@ -1707,7 +1701,6 @@ ncplane_put(ncplane* n, int y, int x, const char* egc, int cols,
}
if(*egc == '\n'){
scroll_down(n);
return 0;
}
// A wide character obliterates anything to its immediate right (and marks
// that cell as wide). Any character placed atop one cell of a wide character
Expand Down Expand Up @@ -1737,18 +1730,20 @@ ncplane_put(ncplane* n, int y, int x, const char* egc, int cols,
}
//fprintf(stderr, "%08x %016lx %c %d %d\n", targ->gcluster, targ->channels, nccell_double_wide_p(targ) ? 'D' : 'd', bytes, cols);
// must set our right hand sides wide, and check for further damage
++n->x;
for(int i = 1 ; i < cols ; ++i){
nccell* candidate = &n->fb[nfbcellidx(n, n->y, n->x)];
int off = nccell_cols(candidate);
nccell_release(n, &n->fb[nfbcellidx(n, n->y, n->x)]);
while(--off > 0){
nccell_obliterate(n, &n->fb[nfbcellidx(n, n->y, n->x + off)]);
}
candidate->channels = targ->channels;
candidate->stylemask = targ->stylemask;
candidate->width = targ->width;
if(*egc != '\n'){
++n->x;
for(int i = 1 ; i < cols ; ++i){
nccell* candidate = &n->fb[nfbcellidx(n, n->y, n->x)];
int off = nccell_cols(candidate);
nccell_release(n, &n->fb[nfbcellidx(n, n->y, n->x)]);
while(--off > 0){
nccell_obliterate(n, &n->fb[nfbcellidx(n, n->y, n->x + off)]);
}
candidate->channels = targ->channels;
candidate->stylemask = targ->stylemask;
candidate->width = targ->width;
++n->x;
}
}
return cols;
}
Expand Down
4 changes: 2 additions & 2 deletions src/tests/cell.cpp
Expand Up @@ -356,13 +356,13 @@ TEST_CASE("Cell") {
CHECK(0 == strcmp(nccell_extended_gcluster(n_, &c), "*"));
}

// only space is allowed
// only space/newline is allowed from control char whitespace
SUBCASE("CellLoadCharWhitespace") {
nccell c = CELL_TRIVIAL_INITIALIZER;
CHECK(-1 == nccell_load_char(n_, &c, '\n'));
CHECK(-1 == nccell_load_char(n_, &c, '\f'));
CHECK(-1 == nccell_load_char(n_, &c, '\v'));
CHECK(-1 == nccell_load_char(n_, &c, '\t'));
CHECK(1 == nccell_load_char(n_, &c, '\n'));
CHECK(1 == nccell_load_char(n_, &c, ' '));
}

Expand Down
4 changes: 2 additions & 2 deletions src/tests/scrolling.cpp
Expand Up @@ -275,7 +275,7 @@ TEST_CASE("Scrolling") {
CHECK(0 == notcurses_render(nc_));
for(unsigned i = 0 ; i < ncplane_dim_y(np) + starty ; ++i){
CHECK(starty - i == ncplane_y(np));
CHECK(0 == ncplane_putchar(n_, '\n'));
CHECK(1 == ncplane_putchar(n_, '\n'));
CHECK(0 == notcurses_render(nc_));
}
CHECK(0 == ncplane_destroy(np));
Expand Down Expand Up @@ -303,7 +303,7 @@ TEST_CASE("Scrolling") {
CHECK(0 == notcurses_render(nc_));
for(unsigned i = 0 ; i < ncplane_dim_y(np) + starty ; ++i){
CHECK(starty == ncplane_y(np));
CHECK(0 == ncplane_putchar(n_, '\n'));
CHECK(1 == ncplane_putchar(n_, '\n'));
CHECK(0 == notcurses_render(nc_));
}
CHECK(0 == ncplane_destroy(np));
Expand Down

0 comments on commit 2e5486a

Please sign in to comment.