Skip to content

Commit 5d906d9

Browse files
miniksamsftbot[bot]
authored and
msftbot[bot]
committed
Patch fix for #1360 until WriteStream (#780) can be implemented. (#2924)
* Patch fix for #1360 until WriteStream (#780) can be implemented. * Add a test that hangs in the broken state and passes in the success stat. Writes a bisecting character to the right most cell in the window. * Code format! *shakes fist at sky* * Update src/cascadia/TerminalCore/Terminal.cpp
1 parent 4dd9f9c commit 5d906d9

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed

src/cascadia/TerminalCore/Terminal.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,18 @@ void Terminal::_WriteBuffer(const std::wstring_view& stringView)
381381
}
382382
}
383383

384+
// If we're about to try to place the cursor past the right edge of the buffer, move it down a row
385+
// This is another patch that GH#780 should supersede. This is really correcting for other bad situations
386+
// like bisecting (writing only the leading half because there's no room for the trailing) a wide character
387+
// into the buffer. However, it's not really all-up correctable without implementing a full WriteStream here.
388+
// Also, this particular code RIGHT HERE shouldn't need to know anything about the cursor or the cells advanced
389+
// which also will be solved by GH#780 (hopefully).
390+
if (proposedCursorPosition.X > bufferSize.RightInclusive())
391+
{
392+
proposedCursorPosition.X = 0;
393+
proposedCursorPosition.Y++;
394+
}
395+
384396
// If we're about to scroll past the bottom of the buffer, instead cycle the buffer.
385397
const auto newRows = proposedCursorPosition.Y - bufferSize.Height() + 1;
386398
if (newRows > 0)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation.
3+
* Licensed under the MIT license.
4+
*/
5+
#include "precomp.h"
6+
#include <WexTestClass.h>
7+
8+
#include "../cascadia/TerminalCore/Terminal.hpp"
9+
#include "../cascadia/UnitTests_TerminalCore/MockTermSettings.h"
10+
#include "../renderer/inc/DummyRenderTarget.hpp"
11+
#include "consoletaeftemplates.hpp"
12+
13+
using namespace WEX::Logging;
14+
using namespace WEX::TestExecution;
15+
16+
using namespace Microsoft::Terminal::Core;
17+
using namespace winrt::Microsoft::Terminal::Settings;
18+
19+
namespace TerminalCoreUnitTests
20+
{
21+
class TerminalApiTests
22+
{
23+
TEST_CLASS(TerminalApiTests);
24+
25+
struct Baton
26+
{
27+
HANDLE ev;
28+
std::wstring text;
29+
Terminal* pTerm;
30+
};
31+
32+
TEST_METHOD(PrintStringOfEmojiBisectingFinalColumn)
33+
{
34+
Terminal term;
35+
DummyRenderTarget emptyRT;
36+
term.Create({ 100, 100 }, 0, emptyRT);
37+
38+
std::wstring textToPrint;
39+
textToPrint.push_back(L'A'); // A is half-width, push it in.
40+
41+
// Put a ton of copies of a full-width emoji here.
42+
const wchar_t* emoji = L"\xD83D\xDE00"; // 1F600 is wide in https://www.unicode.org/Public/UCD/latest/ucd/EastAsianWidth.txt
43+
for (size_t i = 0; i < 120; ++i)
44+
{
45+
textToPrint = textToPrint.append(emoji);
46+
}
47+
48+
Baton b;
49+
b.ev = CreateEventW(nullptr, TRUE, FALSE, L"It is an event");
50+
b.text = textToPrint;
51+
b.pTerm = &term;
52+
53+
Log::Comment(L"Launching thread to write data.");
54+
55+
HANDLE hThread = CreateThread(
56+
nullptr, 0, [](LPVOID c) -> DWORD {
57+
Baton& b = *reinterpret_cast<Baton*>(c);
58+
Log::Comment(L"Writing data.");
59+
b.pTerm->PrintString(b.text);
60+
Log::Comment(L"Setting event.");
61+
SetEvent(b.ev);
62+
return 0;
63+
},
64+
(LPVOID)&b,
65+
0,
66+
nullptr);
67+
68+
Log::Comment(L"Waiting for the write.");
69+
switch (WaitForSingleObject(b.ev, 2000))
70+
{
71+
case WAIT_OBJECT_0:
72+
Log::Comment(L"Didn't get stuck. Success.");
73+
break;
74+
case WAIT_TIMEOUT:
75+
Log::Comment(L"Wait timed out. It got stuck.");
76+
Log::Result(WEX::Logging::TestResults::Failed);
77+
break;
78+
case WAIT_FAILED:
79+
Log::Comment(L"Wait failed for some reason. We didn't expect this.");
80+
Log::Result(WEX::Logging::TestResults::Failed);
81+
break;
82+
default:
83+
Log::Comment(L"Wait return code that no one expected. Fail.");
84+
Log::Result(WEX::Logging::TestResults::Failed);
85+
break;
86+
}
87+
88+
TerminateThread(hThread, 0);
89+
return;
90+
}
91+
};
92+
}

src/cascadia/UnitTests_TerminalCore/UnitTests.vcxproj

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<ClCompile Include="precomp.cpp">
1010
<PrecompiledHeader>Create</PrecompiledHeader>
1111
</ClCompile>
12+
<ClCompile Include="TerminalApiTests.cpp" />
1213
</ItemGroup>
1314
<ItemGroup>
1415
<ProjectReference Include="..\..\buffer\out\lib\bufferout.vcxproj">

0 commit comments

Comments
 (0)