Skip to content

Commit

Permalink
Merge pull request #560 from contour-terminal/fix/ICH
Browse files Browse the repository at this point in the history
[terminal] Fixes ICH.
  • Loading branch information
christianparpart authored Dec 27, 2021
2 parents 6cca21f + 5298f22 commit 9a75096
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 13 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### 0.3.0 (unreleased)

- Fixes VT sequence `ICH` (#559).
- Fixes installation from `.deb` (missing terminfo dependency)
- Improved VT backend performance (#342).
- Improved text selection behaviour.
Expand Down
4 changes: 2 additions & 2 deletions src/terminal/Grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct Margin
{
return unbox<ColumnCount>(to - from) + ColumnCount(1);
}
constexpr bool contains(ColumnOffset _value) const noexcept { return from <= _value && _value < to; }
constexpr bool contains(ColumnOffset _value) const noexcept { return from <= _value && _value <= to; }
constexpr bool operator==(Horizontal rhs) const noexcept { return from == rhs.from && to == rhs.to; }
constexpr bool operator!=(Horizontal rhs) const noexcept { return !(*this == rhs); }
};
Expand All @@ -64,7 +64,7 @@ struct Margin
to; // TODO: call it begin and end and have end point to to+1 to avoid unnecessary +1's later

constexpr LineCount length() const noexcept { return unbox<LineCount>(to - from) + LineCount(1); }
constexpr bool contains(LineOffset _value) const noexcept { return from <= _value && _value < to; }
constexpr bool contains(LineOffset _value) const noexcept { return from <= _value && _value <= to; }
constexpr bool operator==(Vertical const& rhs) const noexcept
{
return from == rhs.from && to == rhs.to;
Expand Down
12 changes: 5 additions & 7 deletions src/terminal/Line.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,18 +235,16 @@ class Line

Cell& useCellAt(ColumnOffset _column) noexcept
{
assert(ColumnOffset(0) <= _column);
assert(_column < ColumnOffset::cast_from(buffer_.size())); // Allow off-by-one for sentinel.
// if constexpr (ColumnOptimized)
// usedColumns_.value.value = std::max(usedColumns_.value.value, _column.value + 1);
return editable().at(unbox<int>(_column));
Require(ColumnOffset(0) <= _column);
Require(_column <= ColumnOffset::cast_from(buffer_.size())); // Allow off-by-one for sentinel.
return editable()[unbox<size_t>(_column)];
}

Cell const& at(ColumnOffset _column) const noexcept
{
Require(ColumnOffset(0) <= _column);
Require(_column < ColumnOffset::cast_from(buffer_.size())); // Allow off-by-one for sentinel.
return buffer_[unbox<int>(_column)];
Require(_column <= ColumnOffset::cast_from(buffer_.size())); // Allow off-by-one for sentinel.
return buffer_[unbox<size_t>(_column)];
}

LineFlags flags() const noexcept { return static_cast<LineFlags>(flags_); }
Expand Down
6 changes: 3 additions & 3 deletions src/terminal/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1357,9 +1357,9 @@ void Screen<T>::insertChars(LineOffset _lineNo, ColumnCount _n)
{
auto const n = min(*_n, *margin_.horizontal.to - *logicalCursorPosition().column + 1);

auto column0 = &at(_lineNo, realCursorPosition().column);
auto column1 = &at(_lineNo, margin_.horizontal.to - ColumnOffset::cast_from(n - 1));
auto column2 = &at(_lineNo, margin_.horizontal.to + ColumnOffset(1));
auto column0 = grid().lineAt(_lineNo).begin() + *realCursorPosition().column;
auto column1 = grid().lineAt(_lineNo).begin() + *margin_.horizontal.to - n + 1;
auto column2 = grid().lineAt(_lineNo).begin() + *margin_.horizontal.to + 1;

rotate(column0, column1, column2);

Expand Down
58 changes: 57 additions & 1 deletion src/terminal/Screen_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,63 @@ TEST_CASE("InsertColumns", "[screen]")
}
}

TEST_CASE("InsertCharacters", "[screen]")
TEST_CASE("InsertCharacters.NoMargins", "[screen]")
{
auto term = MockTerm { PageSize { LineCount(2), ColumnCount(3) } };
auto& screen = term.screen;
screen.write("123\r\n456");
screen.write("\033[2;2H");
REQUIRE("123\n456\n" == screen.renderMainPageText());
REQUIRE(screen.realCursorPosition().line == LineOffset(1));
REQUIRE(screen.realCursorPosition().column == ColumnOffset(1));

SECTION("default")
{
screen.write("\033[@");
REQUIRE("123\n4 5\n" == screen.renderMainPageText());
}

SECTION("ICH: 1 like default")
{
screen.write("\033[1@");
REQUIRE("123\n4 5\n" == screen.renderMainPageText());
}

SECTION("ICH: exact match")
{
screen.write("\033[2@");
REQUIRE("123\n4 \n" == screen.renderMainPageText());
}

SECTION("ICH: one overflow")
{
screen.write("\033[3@");
REQUIRE("123\n4 \n" == screen.renderMainPageText());
}

SECTION("ICH: full line (n-1)")
{
screen.write("\033[2;1H");
screen.write("\033[2@");
REQUIRE("123\n 4\n" == screen.renderMainPageText());
}

SECTION("ICH: full line (n)")
{
screen.write("\033[2;1H");
screen.write("\033[3@");
REQUIRE("123\n \n" == screen.renderMainPageText());
}

SECTION("ICH: full line (n+1)")
{
screen.write("\033[2;1H");
screen.write("\033[4@");
REQUIRE("123\n \n" == screen.renderMainPageText());
}
}

TEST_CASE("InsertCharacters.Margins", "[screen]")
{
auto term = MockTerm { PageSize { LineCount(2), ColumnCount(5) } };
auto& screen = term.screen;
Expand Down

0 comments on commit 9a75096

Please sign in to comment.