Skip to content

Commit

Permalink
Merge branch 'dev/migrie/f/conpty-wrapping-003' into dev/migrie/b/349…
Browse files Browse the repository at this point in the history
…0-resizing-but-no-invalidateall-ing

# Conflicts:
#	src/buffer/out/textBuffer.cpp
#	src/buffer/out/textBuffer.hpp
#	src/host/screenInfo.cpp
  • Loading branch information
zadjii-msft committed Jan 24, 2020
2 parents 8c61481 + 416be46 commit 4248c87
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/host/screenInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,7 @@ bool SCREEN_INFORMATION::IsMaximizedY() const
const short cursorHeightInViewportAfter = newCursor.GetPosition().Y - _viewport.Top();
COORD coordCursorHeightDiff = { 0 };
coordCursorHeightDiff.Y = cursorHeightInViewportAfter - cursorHeightInViewportBefore;

LOG_IF_FAILED(SetViewportOrigin(false, coordCursorHeightDiff, true));

_textBuffer.swap(newTextBuffer);
Expand All @@ -1476,7 +1477,6 @@ bool SCREEN_INFORMATION::IsMaximizedY() const
if (foundWrappedLine || charRow.WasWrapForced())
{
foundWrappedLine = true;
_renderTarget.TriggerRedraw(Viewport::FromDimensions({ 0, y }, _viewport.Width(), 1));
}
}
}
Expand Down
16 changes: 14 additions & 2 deletions src/renderer/vt/XtermEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ XtermEngine::XtermEngine(_In_ wil::unique_hfile hPipe,
_ColorTable(ColorTable),
_cColorTable(cColorTable),
_fUseAsciiOnly(fUseAsciiOnly),
_previousLineWrapped(false),
// _previousLineWrapped(false),
_usingUnderLine(false),
_needToDisableCursor(false),
_lastCursorIsVisible(false),
Expand Down Expand Up @@ -235,6 +235,8 @@ XtermEngine::XtermEngine(_In_ wil::unique_hfile hPipe,
{
HRESULT hr = S_OK;

_trace.TraceMoveCursor(coord);

if (coord.X != _lastText.X || coord.Y != _lastText.Y)
{
if (coord.X == 0 && coord.Y == 0)
Expand All @@ -248,8 +250,15 @@ XtermEngine::XtermEngine(_In_ wil::unique_hfile hPipe,

// If the previous line wrapped, then the cursor is already at this
// position, we just don't know it yet. Don't emit anything.
if (_previousLineWrapped)
bool previousLineWrapped = false;
if (_wrappedRow.has_value())
{
previousLineWrapped = coord.Y == _wrappedRow.value() + 1;
}

if (previousLineWrapped)
{
_trace.TraceWrapped();
hr = S_OK;
}
else
Expand Down Expand Up @@ -298,6 +307,9 @@ XtermEngine::XtermEngine(_In_ wil::unique_hfile hPipe,
_newBottomLine = false;
}
_deferredCursorPos = INVALID_COORDS;

_wrappedRow = std::nullopt;

return hr;
}

Expand Down
29 changes: 27 additions & 2 deletions src/renderer/vt/paint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,6 @@ using namespace Microsoft::Console::Types;
return S_OK;
}

RETURN_IF_FAILED(_MoveCursor(coord));

std::wstring unclusteredString;
unclusteredString.reserve(clusters.size());
short totalWidth = 0;
Expand Down Expand Up @@ -445,10 +443,37 @@ using namespace Microsoft::Console::Types;
(totalWidth - numSpaces) :
totalWidth;

if (cchActual == 0)
{
// If the previous row wrapped, but this line is empty, then we actually
// do want to move the cursor down. Otherwise, we'll possibly end up
// accidentally erasing the last character from the previous line, as
// the cursor is still waiting on that character for the next character
// to follow it.
_wrappedRow = std::nullopt;
// TODO:<Before PR>: Write a test that emulates ~/vttests/reflow-120.py
// TODO:<Before PR>: Write a test that emulates ~/vttests/reflow-advanced.py
}

// Move the cursor to the start of this run.
RETURN_IF_FAILED(_MoveCursor(coord));

// Write the actual text string
std::wstring wstr = std::wstring(unclusteredString.data(), cchActual);
RETURN_IF_FAILED(VtEngine::_WriteTerminalUtf8(wstr));

// If we've written text to the last column of the viewport, then mark
// that we've wrapped this line. The next time we attempt to move the
// cursor, if we're trying to move it to the start of the next line,
// we'll remember that this line was wrapped, and not manually break the
// line.
// Don't do this is the last character we're writing is a space - The last
// char will always be a space, but if we see that, we shouldn't wrap.
if ((_lastText.X + (totalWidth - numSpaces)) > _lastViewport.RightInclusive())
{
_wrappedRow = coord.Y;
}

// Update our internal tracker of the cursor's position.
// See MSFT:20266233
// If the cursor is at the rightmost column of the terminal, and we write a
Expand Down
27 changes: 27 additions & 0 deletions src/renderer/vt/tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,30 @@ void RenderTracing::TraceLastText(const COORD lastTextPos) const
UNREFERENCED_PARAMETER(lastTextPos);
#endif UNIT_TESTING
}

void RenderTracing::TraceMoveCursor(const COORD pos) const
{
#ifndef UNIT_TESTING
const auto lastTextStr = _CoordToString(pos);
const auto cursor = lastTextStr.c_str();
TraceLoggingWrite(g_hConsoleVtRendererTraceProvider,
"VtEngine_TraceMoveCursor",
TraceLoggingString(cursor),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));
#else
UNREFERENCED_PARAMETER(pos);
#endif UNIT_TESTING
}

void RenderTracing::TraceWrapped() const
{
#ifndef UNIT_TESTING
const auto* const msg = "Wrapped instead of \\r\\n";
TraceLoggingWrite(g_hConsoleVtRendererTraceProvider,
"VtEngine_TraceWrapped",
TraceLoggingString(msg),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));
#else
UNREFERENCED_PARAMETER(pos);
#endif UNIT_TESTING
}
2 changes: 2 additions & 0 deletions src/renderer/vt/tracing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ namespace Microsoft::Console::VirtualTerminal
void TraceString(const std::string_view& str) const;
void TraceInvalidate(const Microsoft::Console::Types::Viewport view) const;
void TraceLastText(const COORD lastText) const;
void TraceMoveCursor(const COORD pos) const;
void TraceWrapped() const;
void TraceInvalidateAll(const Microsoft::Console::Types::Viewport view) const;
void TraceTriggerCircling(const bool newFrame) const;
void TraceStartPaint(const bool quickReturn,
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/vt/vtrenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ namespace Microsoft::Console::Render
Microsoft::Console::VirtualTerminal::RenderTracing _trace;
bool _inResizeRequest{ false };

std::optional<short> _wrappedRow{ std::nullopt };

[[nodiscard]] HRESULT _Write(std::string_view const str) noexcept;
[[nodiscard]] HRESULT _WriteFormattedString(const std::string* const pFormat, ...) noexcept;
[[nodiscard]] HRESULT _Flush() noexcept;
Expand Down

0 comments on commit 4248c87

Please sign in to comment.