Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Parpart <[email protected]>
  • Loading branch information
christianparpart committed Apr 10, 2024
1 parent 2d36bb7 commit c90012a
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 151 deletions.
8 changes: 8 additions & 0 deletions cmake/presets/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"LIBUNICODE_TABLEGEN_FASTBUILD": "ON"
}
},
{
"name": "gcc-like-debug",
"hidden": true,
"inherits": ["debug"],
"cacheVariables": {
"CMAKE_CXX_FLAGS_DEBUG": "-O0 -ggdb3 -fno-inline-small-functions -ginline-points -fno-omit-frame-pointer"
}
}
]
}
6 changes: 3 additions & 3 deletions cmake/presets/os-linux.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
{
"name": "linux-debug",
"displayName": "Linux 64-bit",
"inherits": ["linux-common", "debug"]
"inherits": ["linux-common", "gcc-like-debug"]
},
{
"name": "linux-clang-release",
Expand All @@ -55,7 +55,7 @@
{
"name": "linux-clang-debug",
"displayName": "Linux 64-bit (Clang)",
"inherits": ["linux-clang", "debug"]
"inherits": ["linux-clang", "gcc-like-debug"]
},
{
"name": "linux-gcc-release",
Expand All @@ -65,7 +65,7 @@
{
"name": "linux-gcc-debug",
"displayName": "Linux 64-bit (GCC)",
"inherits": ["linux-gcc", "debug"]
"inherits": ["linux-gcc", "gcc-like-debug"]
}
],
"buildPresets": [
Expand Down
2 changes: 1 addition & 1 deletion cmake/presets/os-macos.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{
"name": "macos-debug",
"displayName": "MacOS - Debug",
"inherits": ["macos-common", "debug"]
"inherits": ["macos-common", "gcc-like-debug"]
},
{
"name": "macos-release",
Expand Down
2 changes: 2 additions & 0 deletions src/vtbackend/Line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ struct TrivialLineInflater
auto lineSegmenter = unicode::grapheme_line_segmenter { *this, input.text.view() };
auto result = lineSegmenter.process(std::numeric_limits<unsigned>::max());
assert(result.stop_condition == unicode::StopCondition::EndOfInput);
auto const flushed = lineSegmenter.flush(std::numeric_limits<unsigned>::max());
assert(flushed.stop_condition == unicode::StopCondition::EndOfInput);
vtParserLog()("Inflated {}/{} columns", columns.size(), input.displayWidth);

// Fill remaining columns
Expand Down
220 changes: 110 additions & 110 deletions src/vtbackend/Selector_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,74 +93,74 @@ TEST_CASE("Selector.Linear", "[selector]")
REQUIRE(screen.grid().lineText(LineOffset(1)) == "ab,cdefg,hi");
REQUIRE(screen.grid().lineText(LineOffset(2)) == "12345,67890");

SECTION("single-cell")
{ // "b"
auto const pos = CellLocation { LineOffset(1), ColumnOffset(1) };
auto selector = LinearSelection(selectionHelper, pos, []() {});
(void) selector.extend(pos);
selector.complete();

vector<Selection::Range> const selection = selector.ranges();
REQUIRE(selection.size() == 1);
Selection::Range const& r1 = selection[0];
CHECK(r1.line == pos.line);
CHECK(r1.fromColumn == pos.column);
CHECK(r1.toColumn == pos.column);
CHECK(r1.length() == ColumnCount(1));

auto selectedText = TextSelection { screen };
renderSelection(selector, selectedText);
CHECK(selectedText.text == "b");
}

SECTION("forward single-line")
{ // "b,c"
auto const pos = CellLocation { LineOffset(1), ColumnOffset(1) };
auto selector = LinearSelection(selectionHelper, pos, []() {});
(void) selector.extend(CellLocation { LineOffset(1), ColumnOffset(3) });
selector.complete();

vector<Selection::Range> const selection = selector.ranges();
REQUIRE(selection.size() == 1);
Selection::Range const& r1 = selection[0];
CHECK(r1.line == LineOffset(1));
CHECK(r1.fromColumn == ColumnOffset(1));
CHECK(r1.toColumn == ColumnOffset(3));
CHECK(r1.length() == ColumnCount(3));

auto selectedText = TextSelection { screen };
renderSelection(selector, selectedText);
CHECK(selectedText.text == "b,c");
}

SECTION("forward multi-line")
{ // "b,cdefg,hi\n1234"
auto const pos = CellLocation { LineOffset(1), ColumnOffset(1) };
auto selector = LinearSelection(selectionHelper, pos, []() {});
(void) selector.extend(CellLocation { LineOffset(2), ColumnOffset(3) });
selector.complete();

vector<Selection::Range> const selection = selector.ranges();
REQUIRE(selection.size() == 2);

Selection::Range const& r1 = selection[0];
CHECK(r1.line == LineOffset(1));
CHECK(r1.fromColumn == ColumnOffset(1));
CHECK(r1.toColumn == ColumnOffset(10));
CHECK(r1.length() == ColumnCount(10));

Selection::Range const& r2 = selection[1];
CHECK(r2.line == LineOffset(2));
CHECK(r2.fromColumn == ColumnOffset(0));
CHECK(r2.toColumn == ColumnOffset(3));
CHECK(r2.length() == ColumnCount(4));

auto selectedText = TextSelection { screen };
renderSelection(selector, selectedText);
CHECK(selectedText.text == "b,cdefg,hi\n1234");
}

SECTION("multiple lines fully in history")
// SECTION("single-cell")
// { // "b"
// auto const pos = CellLocation { LineOffset(1), ColumnOffset(1) };
// auto selector = LinearSelection(selectionHelper, pos, []() {});
// (void) selector.extend(pos);
// selector.complete();
//
// vector<Selection::Range> const selection = selector.ranges();
// REQUIRE(selection.size() == 1);
// Selection::Range const& r1 = selection[0];
// CHECK(r1.line == pos.line);
// CHECK(r1.fromColumn == pos.column);
// CHECK(r1.toColumn == pos.column);
// CHECK(r1.length() == ColumnCount(1));
//
// auto selectedText = TextSelection { screen };
// renderSelection(selector, selectedText);
// CHECK(selectedText.text == "b");
// }

// SECTION("forward single-line")
// { // "b,c"
// auto const pos = CellLocation { LineOffset(1), ColumnOffset(1) };
// auto selector = LinearSelection(selectionHelper, pos, []() {});
// (void) selector.extend(CellLocation { LineOffset(1), ColumnOffset(3) });
// selector.complete();
//
// vector<Selection::Range> const selection = selector.ranges();
// REQUIRE(selection.size() == 1);
// Selection::Range const& r1 = selection[0];
// CHECK(r1.line == LineOffset(1));
// CHECK(r1.fromColumn == ColumnOffset(1));
// CHECK(r1.toColumn == ColumnOffset(3));
// CHECK(r1.length() == ColumnCount(3));
//
// auto selectedText = TextSelection { screen };
// renderSelection(selector, selectedText);
// CHECK(selectedText.text == "b,c");
// }

// SECTION("forward multi-line")
// { // "b,cdefg,hi\n1234"
// auto const pos = CellLocation { LineOffset(1), ColumnOffset(1) };
// auto selector = LinearSelection(selectionHelper, pos, []() {});
// (void) selector.extend(CellLocation { LineOffset(2), ColumnOffset(3) });
// selector.complete();
//
// vector<Selection::Range> const selection = selector.ranges();
// REQUIRE(selection.size() == 2);
//
// Selection::Range const& r1 = selection[0];
// CHECK(r1.line == LineOffset(1));
// CHECK(r1.fromColumn == ColumnOffset(1));
// CHECK(r1.toColumn == ColumnOffset(10));
// CHECK(r1.length() == ColumnCount(10));
//
// Selection::Range const& r2 = selection[1];
// CHECK(r2.line == LineOffset(2));
// CHECK(r2.fromColumn == ColumnOffset(0));
// CHECK(r2.toColumn == ColumnOffset(3));
// CHECK(r2.length() == ColumnCount(4));
//
// auto selectedText = TextSelection { screen };
// renderSelection(selector, selectedText);
// CHECK(selectedText.text == "b,cdefg,hi\n1234");
// }

// SECTION("multiple lines fully in history")
{
term.writeToScreen("foo\r\nbar\r\n"); // move first two lines into history.
/*
Expand Down Expand Up @@ -197,48 +197,48 @@ TEST_CASE("Selector.Linear", "[selector]")
CHECK(selectedText.text == "fg,hi\n123");
}

SECTION("multiple lines from history into main buffer")
{
term.writeToScreen("foo\r\nbar\r\n"); // move first two lines into history.
/*
-3 | "12345,67890"
-2 | "ab,cdefg,hi" (--
-1 | "12345,67890" -----------
0 | "foo" --)
1 | "bar"
2 | ""
*/

auto selector =
LinearSelection(selectionHelper, CellLocation { LineOffset(-2), ColumnOffset(8) }, []() {});
(void) selector.extend(CellLocation { LineOffset(0), ColumnOffset(1) });
selector.complete();

vector<Selection::Range> const selection = selector.ranges();
REQUIRE(selection.size() == 3);

Selection::Range const& r1 = selection[0];
CHECK(r1.line == LineOffset(-2));
CHECK(r1.fromColumn == ColumnOffset(8));
CHECK(r1.toColumn == ColumnOffset(10));
CHECK(r1.length() == ColumnCount(3));

Selection::Range const& r2 = selection[1];
CHECK(r2.line == LineOffset(-1));
CHECK(r2.fromColumn == ColumnOffset(0));
CHECK(r2.toColumn == ColumnOffset(10));
CHECK(r2.length() == ColumnCount(11));

Selection::Range const& r3 = selection[2];
CHECK(r3.line == LineOffset(0));
CHECK(r3.fromColumn == ColumnOffset(0));
CHECK(r3.toColumn == ColumnOffset(1));
CHECK(r3.length() == ColumnCount(2));

auto selectedText = TextSelection { screen };
renderSelection(selector, selectedText);
CHECK(selectedText.text == ",hi\n12345,67890\nfo");
}
// SECTION("multiple lines from history into main buffer")
// {
// term.writeToScreen("foo\r\nbar\r\n"); // move first two lines into history.
// /*
// -3 | "12345,67890"
// -2 | "ab,cdefg,hi" (--
// -1 | "12345,67890" -----------
// 0 | "foo" --)
// 1 | "bar"
// 2 | ""
// */
//
// auto selector =
// LinearSelection(selectionHelper, CellLocation { LineOffset(-2), ColumnOffset(8) }, []() {});
// (void) selector.extend(CellLocation { LineOffset(0), ColumnOffset(1) });
// selector.complete();
//
// vector<Selection::Range> const selection = selector.ranges();
// REQUIRE(selection.size() == 3);
//
// Selection::Range const& r1 = selection[0];
// CHECK(r1.line == LineOffset(-2));
// CHECK(r1.fromColumn == ColumnOffset(8));
// CHECK(r1.toColumn == ColumnOffset(10));
// CHECK(r1.length() == ColumnCount(3));
//
// Selection::Range const& r2 = selection[1];
// CHECK(r2.line == LineOffset(-1));
// CHECK(r2.fromColumn == ColumnOffset(0));
// CHECK(r2.toColumn == ColumnOffset(10));
// CHECK(r2.length() == ColumnCount(11));
//
// Selection::Range const& r3 = selection[2];
// CHECK(r3.line == LineOffset(0));
// CHECK(r3.fromColumn == ColumnOffset(0));
// CHECK(r3.toColumn == ColumnOffset(1));
// CHECK(r3.length() == ColumnCount(2));
//
// auto selectedText = TextSelection { screen };
// renderSelection(selector, selectedText);
// CHECK(selectedText.text == ",hi\n12345,67890\nfo");
// }
}

TEST_CASE("Selector.LinearWordWise", "[selector]")
Expand Down
13 changes: 13 additions & 0 deletions src/vtbackend/Sequencer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,22 @@ void Sequencer::error(std::string_view errorString)

void Sequencer::print(char32_t codepoint)
{
if (vtParserLog)
{
if (codepoint < 0x80 && std::isprint(static_cast<char>(codepoint)))
vtParserLog()("Print: '{}'", static_cast<char>(codepoint));
else
vtParserLog()("Print: U+{:X}", (unsigned) codepoint);
}
_terminal.incrementInstructionCounter();
_terminal.sequenceHandler().writeText(codepoint);
}

size_t Sequencer::print(std::string_view chars, size_t cellCount)
{
if (vtParserLog)
vtParserLog()("Print: ({}) '{}'", cellCount, crispy::escape(chars));

assert(!chars.empty());

_terminal.incrementInstructionCounter(chars.size());
Expand All @@ -44,6 +54,9 @@ size_t Sequencer::print(std::string_view chars, size_t cellCount)

void Sequencer::printEnd() noexcept
{
if (vtParserLog)
vtParserLog()("PrintEnd");

_terminal.sequenceHandler().writeTextEnd();
}

Expand Down
Loading

0 comments on commit c90012a

Please sign in to comment.