[glass] Fix ANSI handling at end column (#9011)

Ported from mrccomm
This commit is contained in:
Thad House
2026-06-22 15:55:48 -07:00
committed by GitHub
parent aef281f43d
commit 9ea17c1d53
2 changed files with 11 additions and 2 deletions

View File

@@ -627,9 +627,9 @@ struct AnsiDisplayState::Impl {
size_t TargetColumn =
((CursorColumn / DisplayTabWidth) + 1) * DisplayTabWidth;
TargetColumn = std::min(TargetColumn, MaxDisplayColumnIndex);
do {
while (CursorColumn < TargetColumn) {
WriteCharacter(" ");
} while (CursorColumn < TargetColumn);
}
}
void SetCell(size_t Row, size_t Column, DisplayCell Cell) {

View File

@@ -218,3 +218,12 @@ TEST_CASE("AnsiDisplayStateTest Utf8SplitAcrossApplyCallsWritesOneCell",
CHECK(visitor.runs[0].columns == 1u);
CHECK(visitor.runs[0].text == "X");
}
TEST_CASE("AnsiDisplayState ignores tab at max column", "[AnsiDisplayState]") {
mrc::AnsiDisplayState state;
state.Apply("\x1b[4096GX\t");
std::string snapshot = state.BuildSnapshot();
REQUIRE(snapshot.find("\x1b[1;4096HX") != std::string::npos);
REQUIRE(snapshot.ends_with("\x1b[1;1H\x1b[s\x1b[1;4096H"));
}