From 90882b83295920ad8b007c0f0494c7860c363c0f Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Thu, 19 Sep 2019 11:46:32 -0500 Subject: [PATCH 1/4] fixes #411 --- src/host/screenInfo.cpp | 13 +++++++++++++ src/host/ut_host/ScreenBufferTests.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/host/screenInfo.cpp b/src/host/screenInfo.cpp index 3fabea0bae6..dc54614e9c0 100644 --- a/src/host/screenInfo.cpp +++ b/src/host/screenInfo.cpp @@ -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) { @@ -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; diff --git a/src/host/ut_host/ScreenBufferTests.cpp b/src/host/ut_host/ScreenBufferTests.cpp index 5cb6cd0363e..9e48965e5f9 100644 --- a/src/host/ut_host/ScreenBufferTests.cpp +++ b/src/host/ut_host/ScreenBufferTests.cpp @@ -180,6 +180,8 @@ class ScreenBufferTests TEST_METHOD(RestoreDownAltBufferWithTerminalScrolling); TEST_METHOD(ClearAlternateBuffer); + + TEST_METHOD(InitializeTabStopsInVTMode); }; void ScreenBufferTests::SingleAlternateBufferCreationTest() @@ -4347,3 +4349,25 @@ void ScreenBufferTests::ClearAlternateBuffer() VerifyText(siMain.GetTextBuffer()); } + +void ScreenBufferTests::InitializeTabStopsInVTMode() +{ + // This is a test for microsoft/terminal#1189. Refer to that issue for more + // context + + 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); + + // 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()); +} From cdd0de65b86736e557607acbf40e87ed09d17542 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Thu, 19 Sep 2019 13:08:09 -0500 Subject: [PATCH 2/4] update this comment to actually match --- src/host/ut_host/ScreenBufferTests.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/host/ut_host/ScreenBufferTests.cpp b/src/host/ut_host/ScreenBufferTests.cpp index 9e48965e5f9..c1ba55f5d00 100644 --- a/src/host/ut_host/ScreenBufferTests.cpp +++ b/src/host/ut_host/ScreenBufferTests.cpp @@ -4352,8 +4352,8 @@ void ScreenBufferTests::ClearAlternateBuffer() void ScreenBufferTests::InitializeTabStopsInVTMode() { - // This is a test for microsoft/terminal#1189. Refer to that issue for more - // context + // This is a test for microsoft/terminal#411. Refer to that issue for more + // context. auto& g = ServiceLocator::LocateGlobals(); auto& gci = g.getConsoleInformation(); From aee60275777cdcaf22b1b098eb4c81a987637079 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Thu, 19 Sep 2019 13:39:01 -0500 Subject: [PATCH 3/4] run this test in isolation so it doesn't break other tests, @dhowett-msft --- src/host/ut_host/ScreenBufferTests.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/host/ut_host/ScreenBufferTests.cpp b/src/host/ut_host/ScreenBufferTests.cpp index c1ba55f5d00..71d3aa7ea06 100644 --- a/src/host/ut_host/ScreenBufferTests.cpp +++ b/src/host/ut_host/ScreenBufferTests.cpp @@ -4355,6 +4355,12 @@ 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(); From 86b3eed5acab960034cd1f83b1af57f0ed4f52dd Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Thu, 19 Sep 2019 14:43:36 -0500 Subject: [PATCH 4/4] This fixes the test that's broken? Kinda raises more questions tbh --- src/host/ut_host/SelectionTests.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/host/ut_host/SelectionTests.cpp b/src/host/ut_host/SelectionTests.cpp index d483217f754..7a6aea220de 100644 --- a/src/host/ut_host/SelectionTests.cpp +++ b/src/host/ut_host/SelectionTests.cpp @@ -414,6 +414,7 @@ class SelectionInputTests m_state->PrepareGlobalFont(); m_state->PrepareGlobalScreenBuffer(); + m_state->PrepareGlobalInputBuffer(); return true; } @@ -422,6 +423,7 @@ class SelectionInputTests { m_state->CleanupGlobalScreenBuffer(); m_state->CleanupGlobalFont(); + m_state->CleanupGlobalInputBuffer(); delete m_state;