ttyraster: reset ANSI attributes after each line (#469)

This commit is contained in:
William Chargin 2022-07-09 01:38:35 -07:00 committed by GitHub
parent a9145e7f1e
commit 85aecbda67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 9 deletions

View file

@ -775,7 +775,7 @@ char *ttyraster(char *v, const struct TtyRgb *c, size_t yn, size_t xn,
struct Glyph glyph;
struct TtyRgb chun[4], lastchunk[4];
for (y = 0; y < yn; y += 2, c += xn) {
if (y) *v++ = '\r', *v++ = '\n';
if (y) v = stpcpy(v, "\e[0m\r\n");
for (x = 0; x < xn; x += 2, c += 2) {
CopyChunk(chun, c, xn);
if (ttyquant()->alg == kTtyQuantTrue) {
@ -795,6 +795,6 @@ char *ttyraster(char *v, const struct TtyRgb *c, size_t yn, size_t xn,
memcpy(lastchunk, chun, sizeof(chun));
}
}
*v = '\0';
v = stpcpy(v, "\e[0m");
return v;
}

View file

@ -43,7 +43,7 @@ void ttyraster2x2_true(void) {
TEST(ttyraster, testCorner) {
ttyraster_true_setup();
ttyraster2x2_true();
EXPECT_STREQ("\e[48;2;139;0;0;38;2;3;3;3m▝", vtbuf);
EXPECT_STREQ("\e[48;2;139;0;0;38;2;3;3;3m▝\e[0m", vtbuf);
}
TEST(ttyraster, testFullBlock_favorsSpace) {
@ -54,7 +54,7 @@ TEST(ttyraster, testFullBlock_favorsSpace) {
{DARKRED, DARKRED},
},
2, 2, kBlack, kBlack);
EXPECT_STREQ("\e[48;2;139;0;0m ", vtbuf);
EXPECT_STREQ("\e[48;2;139;0;0m \e[0m", vtbuf);
}
TEST(ttyraster, testFullBlock_favorsUnicodeWhenCurrenttFgMatchesButNotBg) {
@ -65,7 +65,7 @@ TEST(ttyraster, testFullBlock_favorsUnicodeWhenCurrenttFgMatchesButNotBg) {
{DARKRED, DARKRED, GRAY1, GRAY1},
},
2, 4, kBlack, kBlack);
EXPECT_STREQ("\e[48;2;139;0;0;38;2;3;3;3m▝█", vtbuf);
EXPECT_STREQ("\e[48;2;139;0;0;38;2;3;3;3m▝█\e[0m", vtbuf);
}
TEST(ttyraster, testFullBlock_forcesSwitchBackToSpaceForRuns) {
@ -76,7 +76,7 @@ TEST(ttyraster, testFullBlock_forcesSwitchBackToSpaceForRuns) {
{DARKRED, DARKRED, GRAY1, GRAY1, GRAY1, GRAY1, GRAY1, GRAY1},
},
2, 8, kBlack, kBlack);
EXPECT_STREQ("\e[48;2;139;0;0;38;2;3;3;3m▝█\e[48;2;3;3;3m ", vtbuf);
EXPECT_STREQ("\e[48;2;139;0;0;38;2;3;3;3m▝█\e[48;2;3;3;3m \e[0m", vtbuf);
}
////////////////////////////////////////////////////////////////////////////////
@ -89,7 +89,7 @@ TEST(ttyraster_cp437, testSide) {
{DARKRED, GRAY1},
},
2, 2, kBlack, kBlack);
EXPECT_STREQ("\e[48;2;3;3;3;38;2;139;0;0m▌", vtbuf);
EXPECT_STREQ("\e[48;2;3;3;3;38;2;139;0;0m▌\e[0m", vtbuf);
}
////////////////////////////////////////////////////////////////////////////////
@ -110,7 +110,7 @@ void ttyraster2x2_xterm256(void) {
TEST(ttyraster_xterm256, testCorner) {
ttyraster_xterm256_setup();
ttyraster2x2_xterm256();
EXPECT_STREQ("\e[48;5;16;38;5;231m▝", vtbuf);
EXPECT_STREQ("\e[48;5;16;38;5;231m▝\e[0m", vtbuf);
}
void ttyraster6x2_xterm256(void) {
@ -125,7 +125,7 @@ void ttyraster6x2_xterm256(void) {
TEST(ttyraster_xterm256, testCornerRepeat3) {
ttyraster_xterm256_setup();
ttyraster6x2_xterm256();
EXPECT_STREQ("\e[48;5;16;38;5;231m▝▝▝", vtbuf);
EXPECT_STREQ("\e[48;5;16;38;5;231m▝▝▝\e[0m", vtbuf);
}
////////////////////////////////////////////////////////////////////////////////