Skip to content

Commit

Permalink
Update implementation to match spec
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Jun 2, 2020
1 parent e711e11 commit f39807d
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 123 deletions.
3 changes: 3 additions & 0 deletions src/cascadia/TerminalCore/TerminalDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@ bool TerminalDispatch::_PrivateModeParamsHelper(const DispatchTypes::PrivateMode
case DispatchTypes::PrivateModeParams::ATT610_StartCursorBlink:
success = EnableCursorBlinking(enable);
break;
case DispatchTypes::PrivateModeParams::W32IM_Win32InputMode:
success = EnableWin32InputMode(enable);
break;
default:
// If no functions to call, overall dispatch was a failure.
success = false;
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/vt/VtSequences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,5 +448,5 @@ using namespace Microsoft::Console::Render;
// - S_OK if we succeeded, else an appropriate HRESULT for failing to allocate or write.
[[nodiscard]] HRESULT VtEngine::_RequestWin32Input() noexcept
{
return _Write("\x1b]1000;1;1\x07");
return _Write("\x1b[?9001h");
}
3 changes: 2 additions & 1 deletion src/terminal/adapter/DispatchTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ namespace Microsoft::Console::VirtualTerminal::DispatchTypes
UTF8_EXTENDED_MODE = 1005,
SGR_EXTENDED_MODE = 1006,
ALTERNATE_SCROLL = 1007,
ASB_AlternateScreenBuffer = 1049
ASB_AlternateScreenBuffer = 1049,
W32IM_Win32InputMode = 9001
};

enum VTCharacterSets : wchar_t
Expand Down
3 changes: 3 additions & 0 deletions src/terminal/adapter/adaptDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,9 @@ bool AdaptDispatch::_PrivateModeParamsHelper(const DispatchTypes::PrivateModePar
case DispatchTypes::PrivateModeParams::ASB_AlternateScreenBuffer:
success = enable ? UseAlternateScreenBuffer() : UseMainScreenBuffer();
break;
case DispatchTypes::PrivateModeParams::W32IM_Win32InputMode:
success = EnableWin32InputMode(enable);
break;
default:
// If no functions to call, overall dispatch was a failure.
success = false;
Expand Down
12 changes: 6 additions & 6 deletions src/terminal/input/terminalInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,20 +744,20 @@ std::wstring TerminalInput::_GenerateWin32KeySequence(const KeyEvent& key)
{
// Sequences are formatted as follows:
//
// ^[ [ Kd ; Rc ; Vk ; Sc ; Uc ; Cs _
// ^[ [ Vk ; Sc ; Uc ; Kd ; Cs ; Rc _
//
// Kd: the value of bKeyDown - either a '0' or '1'. If omitted, defaults to '0'.
// Rc: the value of wRepeatCount - any number. If omitted, defaults to '0'.
// Vk: the value of wVirtualKeyCode - any number. If omitted, defaults to '0'.
// Sc: the value of wVirtualScanCode - any number. If omitted, defaults to '0'.
// Uc: the decimal value of UnicodeChar - for example, NUL is "0", LF is
// "10", the character 'A' is "65". If omitted, defaults to '0'.
// Kd: the value of bKeyDown - either a '0' or '1'. If omitted, defaults to '0'.
// Cs: the value of dwControlKeyState - any number. If omitted, defaults to '0'.
// Rc: the value of wRepeatCount - any number. If omitted, defaults to '0'.
return fmt::format(L"\x1b[{};{};{};{};{};{}_",
key.IsKeyDown() ? 1 : 0,
key.GetRepeatCount(),
key.GetVirtualKeyCode(),
key.GetVirtualScanCode(),
static_cast<int>(key.GetCharData()),
key.GetActiveModifierKeys());
key.IsKeyDown() ? 1 : 0,
key.GetActiveModifierKeys(),
key.GetRepeatCount());
}
43 changes: 36 additions & 7 deletions src/terminal/parser/InputStateMachineEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1313,16 +1313,45 @@ bool InputStateMachineEngine::_GetSGRXYPosition(const std::basic_string_view<siz
bool InputStateMachineEngine::_GenerateWin32Key(const std::basic_string_view<size_t> parameters,
KeyEvent& key)
{
if (parameters.size() != 6)
// Sequences are formatted as follows:
//
// ^[ [ Vk ; Sc ; Uc ; Kd ; Cs ; Rc _
//
// Vk: the value of wVirtualKeyCode - any number. If omitted, defaults to '0'.
// Sc: the value of wVirtualScanCode - any number. If omitted, defaults to '0'.
// Uc: the decimal value of UnicodeChar - for example, NUL is "0", LF is
// "10", the character 'A' is "65". If omitted, defaults to '0'.
// Kd: the value of bKeyDown - either a '0' or '1'. If omitted, defaults to '0'.
// Cs: the value of dwControlKeyState - any number. If omitted, defaults to '0'.
// Rc: the value of wRepeatCount - any number. If omitted, defaults to '0'.

if (parameters.size() > 6)
{
return false;
}

key = KeyEvent(static_cast<bool>(parameters.at(0)),
::base::saturated_cast<WORD>(parameters.at(1)),
::base::saturated_cast<WORD>(parameters.at(2)),
::base::saturated_cast<WORD>(parameters.at(3)),
static_cast<wchar_t>(parameters.at(4)),
::base::saturated_cast<DWORD>(parameters.at(5)));
key = KeyEvent();
switch (parameters.size())
{
case 6:
key.SetRepeatCount(::base::saturated_cast<WORD>(parameters.at(5)));
[[fallthrough]];
case 5:
key.SetActiveModifierKeys(::base::saturated_cast<DWORD>(parameters.at(4)));
[[fallthrough]];
case 4:
key.SetKeyDown(static_cast<bool>(parameters.at(3)));
[[fallthrough]];
case 3:
key.SetCharData(static_cast<wchar_t>(parameters.at(2)));
[[fallthrough]];
case 2:
key.SetVirtualScanCode(::base::saturated_cast<WORD>(parameters.at(1)));
[[fallthrough]];
case 1:
key.SetVirtualKeyCode(::base::saturated_cast<WORD>(parameters.at(0)));
break;
}

return true;
}
98 changes: 0 additions & 98 deletions src/terminal/parser/OutputStateMachineEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,8 +812,6 @@ bool OutputStateMachineEngine::ActionOscDispatch(const wchar_t /*wch*/,
std::wstring title;
size_t tableIndex = 0;
DWORD color = 0;
size_t windowsTerminalOpcode = 0;
std::wstring_view windowsTerminalParams;

switch (parameter)
{
Expand All @@ -835,9 +833,6 @@ bool OutputStateMachineEngine::ActionOscDispatch(const wchar_t /*wch*/,
color = 0xffffffff;
success = true;
break;
case OscActionCodes::WindowsTerminal:
success = _GetWindowsOperation(string, windowsTerminalOpcode, windowsTerminalParams);
break;
default:
// If no functions to call, overall dispatch was a failure.
success = false;
Expand Down Expand Up @@ -873,10 +868,6 @@ bool OutputStateMachineEngine::ActionOscDispatch(const wchar_t /*wch*/,
success = _dispatch->SetCursorColor(color);
TermTelemetry::Instance().Log(TermTelemetry::Codes::OSCRCC);
break;
case OscActionCodes::WindowsTerminal:
success = _DispatchWindowsCommand(windowsTerminalOpcode, windowsTerminalParams);
TermTelemetry::Instance().Log(TermTelemetry::Codes::OSCWIN);
break;
default:
// If no functions to call, overall dispatch was a failure.
success = false;
Expand Down Expand Up @@ -1836,92 +1827,3 @@ void OutputStateMachineEngine::_ClearLastChar() noexcept
{
_lastPrintedChar = AsciiChars::NUL;
}

// Method Description:
// - Gets the opcode and remaining parameters for a Windows-specifc OSC. These
// sequences are in the format
//
// ^[ ] 1000 ; Op ; <string> ST
//
// where:
// * Op is the opcode as a decimal number, used to identify which
// windows-specific function should be called.
// * <string> can be any string of characters to pass to the specified
// function.
// Arguments:
// - str: An OSC string to parse for an opcode.
// - opcode: receives a number value identifying the function to call.
// - remainingParams: receives the rest of the string following the opcode and
// the `;` that separates them
// Return Value:
// - true if we successfully found an opcode and ';' separating the remaining
// params from the opcode.
bool OutputStateMachineEngine::_GetWindowsOperation(const std::wstring_view str,
size_t& opcode,
std::wstring_view& remainingParams) const
{
// First try to get the table index, a number between [0,256]
size_t opcodeResult = 0;
size_t current = 0;
bool foundTableIndex = false;
for (size_t i = 0; i < str.size(); i++)
{
const wchar_t wch = str.at(current);
if (_isNumber(wch))
{
opcodeResult *= 10;
opcodeResult += wch - L'0';

++current;
}
else if (wch == L';' && i > 0)
{
// We need to explicitly pass in a number, we can't default to 0 if
// there's no param
++current;
foundTableIndex = true;
break;
}
else
{
// Found an unexpected character, fail.
break;
}
}
if (!foundTableIndex)
{
return false;
}
opcode = opcodeResult;
remainingParams = str.substr(current);

return true;
}

// Method Description:
// - Handles dispatching a windows-specific OSC function. The function to be
// exectued should be identified with `opcode`. Each individual function can
// determine how to deal with `remainingParams` on it's own.
// Arguments:
// - opcode: identifies the function to call.
// - remainingParams: a string of characters used as parameters to the specified function.
// Return Value:
// - true if we successfully handled the given function, otherwise false.
bool OutputStateMachineEngine::_DispatchWindowsCommand(const size_t opcode,
const std::wstring_view remainingParams) const
{
switch (opcode)
{
case WindowsOSCFunctions::SetWin32InputMode:
if (remainingParams.size() == 1)
{
const auto wch = remainingParams.at(0);
if (wch == L'0' || wch == L'1')
{
return _dispatch->EnableWin32InputMode(wch == L'1');
}
}
break;
}
return false;
}
9 changes: 1 addition & 8 deletions src/terminal/parser/OutputStateMachineEngine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ namespace Microsoft::Console::VirtualTerminal
SetCursorColor = 12,
ResetForegroundColor = 110, // Not implemented
ResetBackgroundColor = 111, // Not implemented
ResetCursorColor = 112,
WindowsTerminal = 1000
ResetCursorColor = 112
};

enum class DesignateCharsetTypes
Expand Down Expand Up @@ -223,12 +222,6 @@ namespace Microsoft::Console::VirtualTerminal
bool _GetOscTitle(const std::wstring_view string,
std::wstring& title) const;

bool _GetWindowsOperation(const std::wstring_view str,
size_t& opcode,
std::wstring_view& remainingParams) const;
bool _DispatchWindowsCommand(const size_t opcode,
const std::wstring_view remainingParams) const;

static constexpr size_t DefaultTabDistance = 1;
bool _GetTabDistance(const std::basic_string_view<size_t> parameters,
size_t& distance) const noexcept;
Expand Down
1 change: 0 additions & 1 deletion src/terminal/parser/telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ void TermTelemetry::WriteFinalTraceLog() const
TraceLoggingUInt32(_uiTimesUsed[OSCBG], "OscBackgroundColor"),
TraceLoggingUInt32(_uiTimesUsed[REP], "REP"),
TraceLoggingUInt32(_uiTimesUsed[DECALN], "DECALN"),
TraceLoggingUInt32(_uiTimesUsed[OSCWIN], "OSCWIN"),
TraceLoggingUInt32Array(_uiTimesFailed, ARRAYSIZE(_uiTimesFailed), "Failed"),
TraceLoggingUInt32(_uiTimesFailedOutsideRange, "FailedOutsideRange"));
}
Expand Down
1 change: 0 additions & 1 deletion src/terminal/parser/telemetry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ namespace Microsoft::Console::VirtualTerminal
OSCFG,
OSCBG,
DECALN,
OSCWIN,
// Only use this last enum as a count of the number of codes.
NUMBER_OF_CODES
};
Expand Down

1 comment on commit f39807d

@github-actions

This comment was marked as resolved.

Please sign in to comment.