From a8d336416a2be63e25c21fbb4ba51785fd7894fd Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Wed, 2 Mar 2022 06:25:16 -0600 Subject: [PATCH] I thought I could be clever and solve #32 and #12567 at the same time. I was worng. My theory was "fuck perf, let's do it right, and figure out perf later". It didn't work. This wraps lines super weird, probably because I'm copying the whole line to the right side of the row, which is then starting to mark it as wrapped. Also like the test doesn't even pass. --- src/buffer/out/AttrRow.cpp | 8 ++++++++ src/buffer/out/AttrRow.hpp | 3 +++ src/buffer/out/CharRow.cpp | 8 ++++++++ src/buffer/out/CharRow.hpp | 2 ++ src/buffer/out/Row.cpp | 14 ++++++++------ src/host/ut_host/TextBufferTests.cpp | 5 ++++- 6 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/buffer/out/AttrRow.cpp b/src/buffer/out/AttrRow.cpp index 4b5e1888d63..bd4f72366a8 100644 --- a/src/buffer/out/AttrRow.cpp +++ b/src/buffer/out/AttrRow.cpp @@ -122,11 +122,19 @@ ATTR_ROW::const_iterator ATTR_ROW::cbegin() const noexcept { return _data.cbegin(); } +ATTR_ROW::const_reverse_iterator ATTR_ROW::crbegin() const noexcept +{ + return _data.crbegin(); +} ATTR_ROW::const_iterator ATTR_ROW::cend() const noexcept { return _data.cend(); } +ATTR_ROW::const_reverse_iterator ATTR_ROW::crend() const noexcept +{ + return _data.crend(); +} bool operator==(const ATTR_ROW& a, const ATTR_ROW& b) noexcept { diff --git a/src/buffer/out/AttrRow.hpp b/src/buffer/out/AttrRow.hpp index 49756f60805..99b8858ff89 100644 --- a/src/buffer/out/AttrRow.hpp +++ b/src/buffer/out/AttrRow.hpp @@ -29,6 +29,7 @@ class ATTR_ROW final public: using const_iterator = rle_vector::const_iterator; + using const_reverse_iterator = rle_vector::const_reverse_iterator; ATTR_ROW(uint16_t width, TextAttribute attr); @@ -52,7 +53,9 @@ class ATTR_ROW final const_iterator end() const noexcept; const_iterator cbegin() const noexcept; + const_reverse_iterator crbegin() const noexcept; const_iterator cend() const noexcept; + const_reverse_iterator crend() const noexcept; friend bool operator==(const ATTR_ROW& a, const ATTR_ROW& b) noexcept; friend class ROW; diff --git a/src/buffer/out/CharRow.cpp b/src/buffer/out/CharRow.cpp index 40a945c5008..49719595709 100644 --- a/src/buffer/out/CharRow.cpp +++ b/src/buffer/out/CharRow.cpp @@ -76,6 +76,10 @@ typename CharRow::const_iterator CharRow::cbegin() const noexcept { return _data.cbegin(); } +typename CharRow::const_reverse_iterator CharRow::crbegin() const noexcept +{ + return _data.crbegin(); +} typename CharRow::iterator CharRow::end() noexcept { @@ -86,6 +90,10 @@ typename CharRow::const_iterator CharRow::cend() const noexcept { return _data.cend(); } +typename CharRow::const_reverse_iterator CharRow::crend() const noexcept +{ + return _data.crend(); +} // Routine Description: // - Inspects the current internal string to find the left edge of it diff --git a/src/buffer/out/CharRow.hpp b/src/buffer/out/CharRow.hpp index 55d747e8735..67b432ea537 100644 --- a/src/buffer/out/CharRow.hpp +++ b/src/buffer/out/CharRow.hpp @@ -75,10 +75,12 @@ class CharRow final iterator begin() noexcept; const_iterator cbegin() const noexcept; const_iterator begin() const noexcept { return cbegin(); } + const_reverse_iterator crbegin() const noexcept; iterator end() noexcept; const_iterator cend() const noexcept; const_iterator end() const noexcept { return cend(); } + const_reverse_iterator crend() const noexcept; UnicodeStorage& GetUnicodeStorage() noexcept; const UnicodeStorage& GetUnicodeStorage() const noexcept; diff --git a/src/buffer/out/Row.cpp b/src/buffer/out/Row.cpp index 961eb925a2d..0138df79e77 100644 --- a/src/buffer/out/Row.cpp +++ b/src/buffer/out/Row.cpp @@ -205,16 +205,18 @@ size_t ROW::MeasureRightIsh() const // ++it; // } // return _data.crend() - it; - auto charIter = _charRow.cbegin(); - auto attrIter = _attrRow.cbegin(); + auto charIter = _charRow.crbegin(); + auto attrIter = _attrRow.crbegin(); const TextAttribute defaultColor{}; - while (charIter != _charRow.cend() && - attrIter != _attrRow.cend() && + while (charIter != _charRow.crend() && + attrIter != _attrRow.crend() && // (!charIter->IsSpace() || *attrIter != defaultColor)) - (!charIter->IsSpace() || !attrIter->HasIdenticalVisualRepresentationForBlankSpace(defaultColor))) + // (!charIter->IsSpace() || !attrIter->HasIdenticalVisualRepresentationForBlankSpace(defaultColor))) + (charIter->IsSpace() && attrIter->HasIdenticalVisualRepresentationForBlankSpace(defaultColor))) { ++charIter; ++attrIter; } - return charIter - _charRow.cbegin() - 1; + // return charIter - _charRow.cbegin() - 1; + return _charRow.crend() - charIter; } diff --git a/src/host/ut_host/TextBufferTests.cpp b/src/host/ut_host/TextBufferTests.cpp index 24828390284..7ec1123b03c 100644 --- a/src/host/ut_host/TextBufferTests.cpp +++ b/src/host/ut_host/TextBufferTests.cpp @@ -2708,6 +2708,9 @@ void TextBufferTests::NoHyperlinkTrim() void TextBufferTests::TestMeasureRightIsh() { + // Continue on failures + const WEX::TestExecution::DisableVerifyExceptions disableExceptionsScope; + CONSOLE_INFORMATION& gci = ServiceLocator::LocateGlobals().getConsoleInformation(); SCREEN_INFORMATION& si = gci.GetActiveOutputBuffer().GetActiveBuffer(); const TextBuffer& tbi = si.GetTextBuffer(); @@ -2718,7 +2721,7 @@ void TextBufferTests::TestMeasureRightIsh() // const auto foreground = RGB(40, 40, 40); // const auto background = RGB(168, 153, 132); - // const wchar_t* const sequence = L"\x1b[38;2;40;40;40m\x1b[48;2;168;153;132mX\x1b[1mX\x1b[m"; + // TODO! version of the test without the clear and reset to default colors. const wchar_t* const sequence = L"\x1b[0m\x1b[2J\x1b[3JFoo\nBar Baz\n\x1b[41mFoo\n\x1b[42m bar \x1b[44m baz \n\x1b[48m foo \x1b[m"; stateMachine.ProcessString(sequence); // const auto x = cursor.GetPosition().X;