Skip to content

Commit 90882b8

Browse files
committed
fixes #411
1 parent 7128e87 commit 90882b8

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/host/screenInfo.cpp

+13
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

+24
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,25 @@ void ScreenBufferTests::ClearAlternateBuffer()
43474349

43484350
VerifyText(siMain.GetTextBuffer());
43494351
}
4352+
4353+
void ScreenBufferTests::InitializeTabStopsInVTMode()
4354+
{
4355+
// This is a test for microsoft/terminal#1189. Refer to that issue for more
4356+
// context
4357+
4358+
auto& g = ServiceLocator::LocateGlobals();
4359+
auto& gci = g.getConsoleInformation();
4360+
4361+
VERIFY_IS_FALSE(gci.GetActiveOutputBuffer().AreTabsSet());
4362+
4363+
// Enable VT mode before we construct the buffer. This emulates setting the
4364+
// VirtualTerminalLevel reg key before launching the console.
4365+
gci.SetVirtTermLevel(1);
4366+
4367+
// Clean up the old buffer, and re-create it. This new buffer will be
4368+
// created as if the VT mode was always on.
4369+
m_state->CleanupGlobalScreenBuffer();
4370+
m_state->PrepareGlobalScreenBuffer();
4371+
4372+
VERIFY_IS_TRUE(gci.GetActiveOutputBuffer().AreTabsSet());
4373+
}

0 commit comments

Comments
 (0)