Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch fix for #1360 until WriteStream (#780) can be implemented. #2924

Merged
4 commits merged into from
Oct 1, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/cascadia/TerminalCore/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,18 @@ void Terminal::_WriteBuffer(const std::wstring_view& stringView)
}
}

// If we're about to try to place the cursor past the right edge of the buffer, move it down a row
// This is another patch that GH#780 should supercede. This is really correcting for other bad situations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supersede*

DHowett-MSFT marked this conversation as resolved.
Show resolved Hide resolved
// like bisecting (writing only the leading half because there's no room for the trailing) a wide character
// into the buffer. However, it's not really all-up correctable without implementing a full WriteStream here.
// Also, this particular code RIGHT HERE shouldn't need to know anything about the cursor or the cells advanced
// which also will be solved by GH#780 (hopefully).
if (proposedCursorPosition.X > bufferSize.RightInclusive())
{
proposedCursorPosition.X = 0;
proposedCursorPosition.Y++;
}

// If we're about to scroll past the bottom of the buffer, instead cycle the buffer.
const auto newRows = proposedCursorPosition.Y - bufferSize.Height() + 1;
if (newRows > 0)
Expand Down
92 changes: 92 additions & 0 deletions src/cascadia/UnitTests_TerminalCore/TerminalApiTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT license.
*/
#include "precomp.h"
#include <WexTestClass.h>

#include "../cascadia/TerminalCore/Terminal.hpp"
#include "../cascadia/UnitTests_TerminalCore/MockTermSettings.h"
#include "../renderer/inc/DummyRenderTarget.hpp"
#include "consoletaeftemplates.hpp"

using namespace WEX::Logging;
using namespace WEX::TestExecution;

using namespace Microsoft::Terminal::Core;
using namespace winrt::Microsoft::Terminal::Settings;

namespace TerminalCoreUnitTests
{
class TerminalApiTests
{
TEST_CLASS(TerminalApiTests);

struct Baton
{
HANDLE ev;
std::wstring text;
Terminal* pTerm;
};

TEST_METHOD(PrintStringOfEmojiBisectingFinalColumn)
{
Terminal term;
DummyRenderTarget emptyRT;
term.Create({ 100, 100 }, 0, emptyRT);

std::wstring textToPrint;
textToPrint.push_back(L'A'); // A is half-width, push it in.

// Put a ton of copies of a full-width emoji here.
const wchar_t* emoji = L"\xD83D\xDE00"; // 1F600 is wide in https://www.unicode.org/Public/UCD/latest/ucd/EastAsianWidth.txt
for (size_t i = 0; i < 120; ++i)
{
textToPrint = textToPrint.append(emoji);
}

Baton b;
b.ev = CreateEventW(nullptr, TRUE, FALSE, L"It is an event");
b.text = textToPrint;
b.pTerm = &term;

Log::Comment(L"Launching thread to write data.");

HANDLE hThread = CreateThread(
nullptr, 0, [](LPVOID c) -> DWORD {
Baton& b = *reinterpret_cast<Baton*>(c);
Log::Comment(L"Writing data.");
b.pTerm->PrintString(b.text);
Log::Comment(L"Setting event.");
SetEvent(b.ev);
return 0;
},
(LPVOID)& b,
0,
nullptr);

Log::Comment(L"Waiting for the write.");
switch (WaitForSingleObject(b.ev, 2000))
{
case WAIT_OBJECT_0:
Log::Comment(L"Didn't get stuck. Success.");
break;
case WAIT_TIMEOUT:
Log::Comment(L"Wait timed out. It got stuck.");
Log::Result(WEX::Logging::TestResults::Failed);
break;
case WAIT_FAILED:
Log::Comment(L"Wait failed for some reason. We didn't expect this.");
Log::Result(WEX::Logging::TestResults::Failed);
break;
default:
Log::Comment(L"Wait return code that no one expected. Fail.");
Log::Result(WEX::Logging::TestResults::Failed);
break;
}

TerminateThread(hThread, 0);
return;
}
};
}
3 changes: 2 additions & 1 deletion src/cascadia/UnitTests_TerminalCore/UnitTests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<ClCompile Include="precomp.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="TerminalApiTests.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\buffer\out\lib\bufferout.vcxproj">
Expand Down Expand Up @@ -51,4 +52,4 @@
<Import Project="$(SolutionDir)src\common.build.dll.props" />
<Import Project="$(SolutionDir)src\common.build.post.props" />
<Import Project="$(SolutionDir)src\common.build.tests.props" />
</Project>
</Project>