Fix automerge at border (#515)

This commit is contained in:
Fredrik Hallenberg 2022-11-25 00:39:17 +01:00 committed by GitHub
parent 121bd0d046
commit 55b9706cfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 9 deletions

View File

@ -708,6 +708,28 @@ TEST(TableTest, RowFlexTwo) {
screen.ToString()); screen.ToString());
} }
TEST(TableTest, Merge) {
auto table = Table({
{"a", "b", "c"},
{"d", "e", "f"},
{"g", "h", "i"},
});
table.SelectAll().Border(LIGHT);
table.SelectColumn(1).Border(HEAVY);
table.SelectRow(1).Border(HEAVY);
Screen screen(7, 7);
Render(screen, table.Render());
EXPECT_EQ(
"┌─┲━┱─┐\r\n"
"│a┃b┃c│\r\n"
"┢━╋━╋━┪\r\n"
"┃d┃e┃f┃\r\n"
"┡━╋━╋━┩\r\n"
"│g┃h┃i│\r\n"
"└─┺━┹─┘",
screen.ToString());
}
} // namespace ftxui } // namespace ftxui
// Copyright 2021 Arthur Sonzogni. All rights reserved. // Copyright 2021 Arthur Sonzogni. All rights reserved.

View File

@ -501,22 +501,25 @@ void Screen::Clear() {
// clang-format off // clang-format off
void Screen::ApplyShader() { void Screen::ApplyShader() {
// Merge box characters togethers. // Merge box characters togethers.
for (int y = 1; y < dimy_; ++y) { for (int y = 0; y < dimy_; ++y) {
for (int x = 1; x < dimx_; ++x) { for (int x = 0; x < dimx_; ++x) {
// Box drawing character uses exactly 3 byte. // Box drawing character uses exactly 3 byte.
Pixel& cur = pixels_[y][x]; Pixel& cur = pixels_[y][x];
if (!ShouldAttemptAutoMerge(cur)) { if (!ShouldAttemptAutoMerge(cur)) {
continue; continue;
} }
Pixel& left = pixels_[y][x-1]; if (x > 0) {
Pixel& top = pixels_[y-1][x]; Pixel& left = pixels_[y][x-1];
if (ShouldAttemptAutoMerge(left)) {
if (ShouldAttemptAutoMerge(left)) { UpgradeLeftRight(left.character, cur.character);
UpgradeLeftRight(left.character, cur.character); }
} }
if (ShouldAttemptAutoMerge(top)) { if (y > 0) {
UpgradeTopDown(top.character, cur.character); Pixel& top = pixels_[y-1][x];
if (ShouldAttemptAutoMerge(top)) {
UpgradeTopDown(top.character, cur.character);
}
} }
} }
} }