Skip to content

Commit

Permalink
Try to wrap the line properly with conpty
Browse files Browse the repository at this point in the history
  This confusingly doesn't always work
  • Loading branch information
zadjii-msft committed Jan 13, 2020
1 parent 9aec694 commit 1a2654d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
13 changes: 11 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 @@ -248,7 +248,13 @@ 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)
{
hr = S_OK;
}
Expand Down Expand Up @@ -298,6 +304,9 @@ XtermEngine::XtermEngine(_In_ wil::unique_hfile hPipe,
_newBottomLine = false;
}
_deferredCursorPos = INVALID_COORDS;

_wrappedRow = std::nullopt;

return hr;
}

Expand Down
15 changes: 15 additions & 0 deletions src/renderer/vt/paint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,21 @@ using namespace Microsoft::Console::Types;
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

This comment has been minimized.

Copy link
@HBelusca

HBelusca Jan 15, 2020

Contributor

s/is/if/

// char will always be a space, but if we see that, we shouldn't wrap.

// TODO: This seems to be off by one char. Resizing cmd.exe, the '.' at the
// end of the initial message sometimes gets cut off weirdly.
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
2 changes: 2 additions & 0 deletions src/renderer/vt/vtrenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,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 1a2654d

Please sign in to comment.