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

Added Escape Key to CharacterHandler so it can be handled instead of returned. #1981

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion samples/ConPTY/MiniTerm/MiniTerm/Terminal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private static void CopyInputToPipe(SafeFileHandle inputWriteSide)
writer.AutoFlush = true;
writer.WriteLine(@"cd \");

while (true)
for (;;)
{
// send input character-by-character to the pipe
char key = Console.ReadKey(intercept: true).KeyChar;
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalConnection/ConhostConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
std::string_view strView{};

// process the data of the output pipe in a loop
while (true)
for (;;)
{
HRESULT result = pipeReader.Read(strView);
if (FAILED(result))
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalConnection/ConptyConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
{
BYTE buffer[256];
DWORD dwRead;
while (true)
for (;;)
{
dwRead = 0;
bool fSuccess = false;
Expand Down
9 changes: 8 additions & 1 deletion src/cascadia/TerminalCore/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,14 @@ bool Terminal::SendKeyEvent(const WORD vkey, const ControlKeyStates states)
}
}

if (states.IsCtrlPressed())
// Manually handle Escape here. If we let it fall through, it'll come
// back up through the character handler. It's registered as a translation
// in TerminalInput, so we'll let TerminalInput control it.
if (vkey == VK_ESCAPE)
{
ch = UNICODE_ESC;
}
else if (states.IsCtrlPressed())
{
switch (vkey)
{
Expand Down
2 changes: 1 addition & 1 deletion src/host/cmdline.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Revision History:
return ProcessCommandListInput

ProcessCommandListInput
while (TRUE)
for (;;)
GetChar
if (wait)
return wait
Expand Down
2 changes: 1 addition & 1 deletion src/host/ft_host/API_InputTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ void InputTests::TestReadConsolePasswordScenario()
VERIFY_IS_NOT_NULL(buf);
wchar_t* bufPtr = buf.get();

while (true)
for (;;)
{
wchar_t ch;
DWORD c;
Expand Down
6 changes: 3 additions & 3 deletions src/host/ft_uia/AccessibilityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ public void CanMoveRange()
visibleRanges = textPattern.GetVisibleRanges();
testRange = visibleRanges.First().Clone();
// move range back to the top
while (true)
for (;;)
{
int moveCount = testRange.Move(TextUnit.Line, -1);
if (moveCount == 0)
Expand Down Expand Up @@ -512,7 +512,7 @@ public void CanMoveEndpointByUnitNearTopBoundary()
// move all the way to the bottom
visibleRanges = textPattern.GetVisibleRanges();
testRange = visibleRanges.Last().Clone();
while (true)
for (;;)
{
int moved = testRange.Move(TextUnit.Line, 1);
if (moved == 0)
Expand Down Expand Up @@ -571,7 +571,7 @@ public void CanMoveEndpointByUnitNearBottomBoundary()
// move all the way to the top
visibleRanges = textPattern.GetVisibleRanges();
testRange = visibleRanges.First().Clone();
while (true)
for (;;)
{
int moved = testRange.Move(TextUnit.Line, -1);
if (moved == 0)
Expand Down
1 change: 1 addition & 0 deletions src/inc/unicode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Author(s):

// UNICODE_NULL is a Windows macro definition
const wchar_t UNICODE_BACKSPACE = 0x8;
const wchar_t UNICODE_ESC = 0x1b;
const wchar_t UNICODE_DEL = 0x7f;
// NOTE: This isn't actually a backspace. It's a graphical block. But
// I believe it's emitted by one of our ANSI/OEM --> Unicode conversions.
Expand Down
41 changes: 19 additions & 22 deletions src/interactivity/onecore/ConIoSrvComm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ VOID ConIoSrvComm::ServiceInputPipe()

CIS_EVENT Event = { 0 };

while (TRUE)
for (;;)
{
Ret = ReadFile(_pipeReadHandle,
&Event,
Expand Down Expand Up @@ -394,28 +394,25 @@ VOID ConIoSrvComm::HandleFocusEvent(PCIS_EVENT Event)
}
}
}
else
else if (pWddmConEngine->IsInitialized())
{
if (pWddmConEngine->IsInitialized())
{
// Wait for the currently running paint operation, if any,
// and prevent further attempts to render.
Renderer->WaitForPaintCompletionAndDisable(1000);

// Relinquish control of the graphics device (only one
// DirectX application may control the device at any one
// time).
LOG_IF_FAILED(pWddmConEngine->Disable());

// Let the Console IO Server that we have relinquished
// control of the display.
ReplyEvent.Type = CIS_EVENT_TYPE_FOCUS_ACK;
Ret = WriteFile(_pipeWriteHandle,
&ReplyEvent,
sizeof(CIS_EVENT),
NULL,
NULL);
}
// Wait for the currently running paint operation, if any,
// and prevent further attempts to render.
Renderer->WaitForPaintCompletionAndDisable(1000);

// Relinquish control of the graphics device (only one
// DirectX application may control the device at any one
// time).
LOG_IF_FAILED(pWddmConEngine->Disable());

// Let the Console IO Server that we have relinquished
// control of the display.
ReplyEvent.Type = CIS_EVENT_TYPE_FOCUS_ACK;
Ret = WriteFile(_pipeWriteHandle,
&ReplyEvent,
sizeof(CIS_EVENT),
NULL,
NULL);
}
}
break;
Expand Down
7 changes: 2 additions & 5 deletions src/server/ApiSorter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,12 @@ PCONSOLE_API_MSG ApiSorter::ConsoleDispatchRequest(_Inout_ PCONSOLE_API_MSG Mess
Status = NTSTATUS_FROM_HRESULT(Status);
}

if (!ReplyPending)
if (ReplyPending)
{
goto Complete;
return nullptr;
}

return nullptr;

Complete:

Message->SetReplyStatus(Status);

return Message;
Expand Down
16 changes: 5 additions & 11 deletions src/server/IoDispatchers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ PCONSOLE_API_MSG IoDispatchers::ConsoleCreateObject(_In_ PCONSOLE_API_MSG pMessa

if (!NT_SUCCESS(Status))
{
goto Error;
//ERROR!!
FAIL_FAST_IF(NT_SUCCESS(Status));
UnlockConsole();
pMessage->SetReplyStatus(Status);
return pMessage;
}

// Complete the request.
Expand All @@ -102,16 +106,6 @@ PCONSOLE_API_MSG IoDispatchers::ConsoleCreateObject(_In_ PCONSOLE_API_MSG pMessa
UnlockConsole();

return nullptr;

Error:

FAIL_FAST_IF(NT_SUCCESS(Status));

UnlockConsole();

pMessage->SetReplyStatus(Status);

return pMessage;
}

// Routine Description:
Expand Down
4 changes: 2 additions & 2 deletions src/server/WaitQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ bool ConsoleWaitQueue::NotifyWaiters(const bool fNotifyAll,
ConsoleWaitBlock* const WaitBlock = (*it);
if (nullptr == WaitBlock)
{
break;
return fResult;
}

auto const nextIt = std::next(it); // we have to capture next before it is potentially erased
Expand All @@ -94,7 +94,7 @@ bool ConsoleWaitQueue::NotifyWaiters(const bool fNotifyAll,

if (!fNotifyAll)
{
break;
return fResult;
}

it = nextIt;
Expand Down
13 changes: 5 additions & 8 deletions src/terminal/adapter/MouseInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ MouseInput::~MouseInput()
// - true iff uiButton is a button message to translate
bool MouseInput::s_IsButtonMsg(const unsigned int uiButton)
{
bool fIsButton = false;
switch (uiButton)
{
case WM_LBUTTONDBLCLK:
Expand All @@ -61,10 +60,10 @@ bool MouseInput::s_IsButtonMsg(const unsigned int uiButton)
case WM_MBUTTONDBLCLK:
case WM_MOUSEWHEEL:
case WM_MOUSEHWHEEL:
fIsButton = true;
break;
return true;
default:
return false;
}
return fIsButton;
}

// Routine Description:
Expand All @@ -87,7 +86,6 @@ bool MouseInput::s_IsHoverMsg(const unsigned int uiButtonCode)
// - true iff uiButton is a button down event
bool MouseInput::s_IsButtonDown(const unsigned int uiButton)
{
bool fIsButtonDown = false;
switch (uiButton)
{
case WM_LBUTTONDBLCLK:
Expand All @@ -98,10 +96,9 @@ bool MouseInput::s_IsButtonDown(const unsigned int uiButton)
case WM_MBUTTONDBLCLK:
case WM_MOUSEWHEEL:
case WM_MOUSEHWHEEL:
fIsButtonDown = true;
break;
return true;
}
return fIsButtonDown;
return false;
}

// Routine Description:
Expand Down
2 changes: 1 addition & 1 deletion src/tools/nihilist/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// This keeps a console session alive and doesn't interfere with tests or other hooks.
int __cdecl wmain(int /*argc*/, WCHAR* /*argv[]*/)
{
while (true)
for (;;)
{
SleepEx(INFINITE, FALSE);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/vtapp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static void Main(string[] args)

Console.WriteLine("VT Tester");

while (true)
for (;;)
{
ConsoleKeyInfo keyInfo = Console.ReadKey(true);

Expand Down
2 changes: 1 addition & 1 deletion src/tools/vtapp/Program2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static void Main2(string[] args)
}
if (!fSuccess) return;

while (true)
for (;;)
{
ConsoleKeyInfo keyInfo = Console.ReadKey(false);
switch (keyInfo.KeyChar)
Expand Down
2 changes: 1 addition & 1 deletion src/tools/vtpipeterm/VtConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ DWORD VtConsole::_OutputThread()
{
BYTE buffer[256];
DWORD dwRead;
while (true)
for (;;)
{
dwRead = 0;
bool fSuccess = false;
Expand Down
9 changes: 3 additions & 6 deletions src/tsf/TfEditses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1139,13 +1139,10 @@ CEditSessionObject::Release()
// Create Cicero Display Attribute Manager
//
pTmpDispAttr = new (std::nothrow) CicDisplayAttributeMgr;
if (pTmpDispAttr)
if (pTmpDispAttr && SUCCEEDED(hr = pTmpDispAttr->InitDisplayAttributeInstance(pcat)))
{
if (SUCCEEDED(hr = pTmpDispAttr->InitDisplayAttributeInstance(pcat)))
{
*pCicCatMgr = pTmpCat;
*pCicDispAttr = pTmpDispAttr;
}
*pCicCatMgr = pTmpCat;
*pCicDispAttr = pTmpDispAttr;
}
}
}
Expand Down