Skip to content

Commit 7ab4e85

Browse files
zadjii-msftDHowett
authored andcommitted
Initialize the VT tab stops when a buffer is created in VT mode (#2816)
* fixes #411 * update this comment to actually match * run this test in isolation so it doesn't break other tests, @DHowett-MSFT * This fixes the test that's broken? Kinda raises more questions tbh (cherry picked from commit dfaaa44)
1 parent b2f83c3 commit 7ab4e85

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

src/host/screenInfo.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ SCREEN_INFORMATION::SCREEN_INFORMATION(
6868
LineChar[3] = UNICODE_BOX_DRAW_LIGHT_VERTICAL;
6969
LineChar[4] = UNICODE_BOX_DRAW_LIGHT_UP_AND_RIGHT;
7070
LineChar[5] = UNICODE_BOX_DRAW_LIGHT_UP_AND_LEFT;
71+
72+
// Check if VT mode is enabled. Note that this can be true w/o calling
73+
// SetConsoleMode, if VirtualTerminalLevel is set to !=0 in the registry.
7174
const CONSOLE_INFORMATION& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
7275
if (gci.GetVirtTermLevel() != 0)
7376
{
@@ -132,6 +135,16 @@ SCREEN_INFORMATION::~SCREEN_INFORMATION()
132135

133136
const NTSTATUS status = pScreen->_InitializeOutputStateMachine();
134137

138+
if (pScreen->InVTMode())
139+
{
140+
// microsoft/terminal#411: If VT mode is enabled, lets construct the
141+
// VT tab stops. Without this line, if a user has
142+
// VirtualTerminalLevel set, then
143+
// SetConsoleMode(ENABLE_VIRTUAL_TERMINAL_PROCESSING) won't set our
144+
// tab stops, because we're never going from vt off -> on
145+
pScreen->SetDefaultVtTabStops();
146+
}
147+
135148
if (NT_SUCCESS(status))
136149
{
137150
*ppScreen = pScreen;

src/host/ut_host/ScreenBufferTests.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ class ScreenBufferTests
180180
TEST_METHOD(RestoreDownAltBufferWithTerminalScrolling);
181181

182182
TEST_METHOD(ClearAlternateBuffer);
183+
184+
TEST_METHOD(InitializeTabStopsInVTMode);
183185
};
184186

185187
void ScreenBufferTests::SingleAlternateBufferCreationTest()
@@ -4347,3 +4349,31 @@ void ScreenBufferTests::ClearAlternateBuffer()
43474349

43484350
VerifyText(siMain.GetTextBuffer());
43494351
}
4352+
4353+
void ScreenBufferTests::InitializeTabStopsInVTMode()
4354+
{
4355+
// This is a test for microsoft/terminal#411. Refer to that issue for more
4356+
// context.
4357+
4358+
// Run this test in isolation - Let's not pollute the VT level for other
4359+
// tests, or go blowing away other test's buffers
4360+
BEGIN_TEST_METHOD_PROPERTIES()
4361+
TEST_METHOD_PROPERTY(L"IsolationLevel", L"Method")
4362+
END_TEST_METHOD_PROPERTIES()
4363+
4364+
auto& g = ServiceLocator::LocateGlobals();
4365+
auto& gci = g.getConsoleInformation();
4366+
4367+
VERIFY_IS_FALSE(gci.GetActiveOutputBuffer().AreTabsSet());
4368+
4369+
// Enable VT mode before we construct the buffer. This emulates setting the
4370+
// VirtualTerminalLevel reg key before launching the console.
4371+
gci.SetVirtTermLevel(1);
4372+
4373+
// Clean up the old buffer, and re-create it. This new buffer will be
4374+
// created as if the VT mode was always on.
4375+
m_state->CleanupGlobalScreenBuffer();
4376+
m_state->PrepareGlobalScreenBuffer();
4377+
4378+
VERIFY_IS_TRUE(gci.GetActiveOutputBuffer().AreTabsSet());
4379+
}

src/host/ut_host/SelectionTests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ class SelectionInputTests
414414

415415
m_state->PrepareGlobalFont();
416416
m_state->PrepareGlobalScreenBuffer();
417+
m_state->PrepareGlobalInputBuffer();
417418

418419
return true;
419420
}
@@ -422,6 +423,7 @@ class SelectionInputTests
422423
{
423424
m_state->CleanupGlobalScreenBuffer();
424425
m_state->CleanupGlobalFont();
426+
m_state->CleanupGlobalInputBuffer();
425427

426428
delete m_state;
427429

0 commit comments

Comments
 (0)