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

Initialize the VT tab stops when a buffer is created in VT mode #2816

Merged
merged 4 commits into from
Sep 19, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
13 changes: 13 additions & 0 deletions src/host/screenInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ SCREEN_INFORMATION::SCREEN_INFORMATION(
LineChar[3] = UNICODE_BOX_DRAW_LIGHT_VERTICAL;
LineChar[4] = UNICODE_BOX_DRAW_LIGHT_UP_AND_RIGHT;
LineChar[5] = UNICODE_BOX_DRAW_LIGHT_UP_AND_LEFT;

// Check if VT mode is enabled. Note that this can be true w/o calling
// SetConsoleMode, if VirtualTerminalLevel is set to !=0 in the registry.
const CONSOLE_INFORMATION& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
if (gci.GetVirtTermLevel() != 0)
{
Expand Down Expand Up @@ -132,6 +135,16 @@ SCREEN_INFORMATION::~SCREEN_INFORMATION()

const NTSTATUS status = pScreen->_InitializeOutputStateMachine();

if (pScreen->InVTMode())
{
// microsoft/terminal#411: If VT mode is enabled, lets construct the
// VT tab stops. Without this line, if a user has
// VirtualTerminalLevel set, then
// SetConsoleMode(ENABLE_VIRTUAL_TERMINAL_PROCESSING) won't set our
// tab stops, because we're never going from vt off -> on
pScreen->SetDefaultVtTabStops();
}

if (NT_SUCCESS(status))
{
*ppScreen = pScreen;
Expand Down
30 changes: 30 additions & 0 deletions src/host/ut_host/ScreenBufferTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ class ScreenBufferTests
TEST_METHOD(RestoreDownAltBufferWithTerminalScrolling);

TEST_METHOD(ClearAlternateBuffer);

TEST_METHOD(InitializeTabStopsInVTMode);
};

void ScreenBufferTests::SingleAlternateBufferCreationTest()
Expand Down Expand Up @@ -4347,3 +4349,31 @@ void ScreenBufferTests::ClearAlternateBuffer()

VerifyText(siMain.GetTextBuffer());
}

void ScreenBufferTests::InitializeTabStopsInVTMode()
{
// This is a test for microsoft/terminal#411. Refer to that issue for more
// context.

// Run this test in isolation - Let's not pollute the VT level for other
// tests, or go blowing away other test's buffers
BEGIN_TEST_METHOD_PROPERTIES()
TEST_METHOD_PROPERTY(L"IsolationLevel", L"Method")
END_TEST_METHOD_PROPERTIES()

auto& g = ServiceLocator::LocateGlobals();
auto& gci = g.getConsoleInformation();

VERIFY_IS_FALSE(gci.GetActiveOutputBuffer().AreTabsSet());

// Enable VT mode before we construct the buffer. This emulates setting the
// VirtualTerminalLevel reg key before launching the console.
gci.SetVirtTermLevel(1);
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved

// Clean up the old buffer, and re-create it. This new buffer will be
// created as if the VT mode was always on.
m_state->CleanupGlobalScreenBuffer();
m_state->PrepareGlobalScreenBuffer();

VERIFY_IS_TRUE(gci.GetActiveOutputBuffer().AreTabsSet());
}