mirror of
https://github.com/microsoft/terminal.git
synced 2025-12-11 04:38:24 -06:00
Improvements to TerminalInput (#690)
* Specified the destructor of TerminalInput as default * Simplified GetKeymappingLength * Simplified GetKeyMapping * Removed a redundant assignment * Added auto deduction to some variables * Merged the public sections of TerminalInput * Implied the destructor for TerminalInput * Removed GetKeyMappingLength and GetKeyMapping from public interface Rearranged public section to be above private. * Deleted or defaulted all six special member functions. * Removed extraneous newlines * Deleted all move and copy operations. The default constructor is also deleted. The destructor is defaulted. * Converted tabs to 4 spaces
This commit is contained in:
parent
1c16b2c06b
commit
dadd74c3c6
@ -25,11 +25,6 @@ TerminalInput::TerminalInput(_In_ std::function<void(std::deque<std::unique_ptr<
|
||||
_pfnWriteEvents = pfn;
|
||||
}
|
||||
|
||||
TerminalInput::~TerminalInput()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// See http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-PC-Style-Function-Keys
|
||||
// For the source for these tables.
|
||||
// Also refer to the values in terminfo for kcub1, kcud1, kcuf1, kcuu1, kend, khome.
|
||||
@ -215,31 +210,22 @@ void TerminalInput::ChangeCursorKeysMode(const bool fApplicationMode)
|
||||
|
||||
const size_t TerminalInput::GetKeyMappingLength(const KeyEvent& keyEvent) const
|
||||
{
|
||||
size_t length = 0;
|
||||
if (keyEvent.IsCursorKey())
|
||||
{
|
||||
length = (_fCursorApplicationMode) ? s_cCursorKeysApplicationMapping : s_cCursorKeysNormalMapping;
|
||||
return (_fCursorApplicationMode) ? s_cCursorKeysApplicationMapping : s_cCursorKeysNormalMapping;
|
||||
}
|
||||
else
|
||||
{
|
||||
length = (_fKeypadApplicationMode) ? s_cKeypadApplicationMapping : s_cKeypadNumericMapping;
|
||||
}
|
||||
return length;
|
||||
|
||||
return (_fKeypadApplicationMode) ? s_cKeypadApplicationMapping : s_cKeypadNumericMapping;
|
||||
}
|
||||
|
||||
const TerminalInput::_TermKeyMap* TerminalInput::GetKeyMapping(const KeyEvent& keyEvent) const
|
||||
{
|
||||
const TerminalInput::_TermKeyMap* mapping = nullptr;
|
||||
|
||||
if (keyEvent.IsCursorKey())
|
||||
{
|
||||
mapping = (_fCursorApplicationMode) ? s_rgCursorKeysApplicationMapping : s_rgCursorKeysNormalMapping;
|
||||
return (_fCursorApplicationMode) ? s_rgCursorKeysApplicationMapping : s_rgCursorKeysNormalMapping;
|
||||
}
|
||||
else
|
||||
{
|
||||
mapping = (_fKeypadApplicationMode) ? s_rgKeypadApplicationMapping : s_rgKeypadNumericMapping;
|
||||
}
|
||||
return mapping;
|
||||
|
||||
return (_fKeypadApplicationMode) ? s_rgKeypadApplicationMapping : s_rgKeypadNumericMapping;
|
||||
}
|
||||
|
||||
// Routine Description:
|
||||
@ -375,11 +361,10 @@ bool TerminalInput::_TranslateDefaultMapping(const KeyEvent& keyEvent,
|
||||
const size_t cKeyMapping) const
|
||||
{
|
||||
const TerminalInput::_TermKeyMap* pMatchingMapping;
|
||||
bool fSuccess = _SearchKeyMapping(keyEvent, keyMapping, cKeyMapping, &pMatchingMapping);
|
||||
const bool fSuccess = _SearchKeyMapping(keyEvent, keyMapping, cKeyMapping, &pMatchingMapping);
|
||||
if (fSuccess)
|
||||
{
|
||||
_SendInputSequence(pMatchingMapping->pwszSequence);
|
||||
fSuccess = true;
|
||||
}
|
||||
return fSuccess;
|
||||
}
|
||||
@ -392,7 +377,7 @@ bool TerminalInput::HandleKey(const IInputEvent* const pInEvent) const
|
||||
// On key presses, prepare to translate to VT compatible sequences
|
||||
if (pInEvent->EventType() == InputEventType::KeyEvent)
|
||||
{
|
||||
KeyEvent keyEvent = *static_cast<const KeyEvent* const>(pInEvent);
|
||||
auto keyEvent = *static_cast<const KeyEvent* const>(pInEvent);
|
||||
|
||||
// Only need to handle key down. See raw key handler (see RawReadWaitRoutine in stream.cpp)
|
||||
if (keyEvent.IsKeyDown())
|
||||
@ -427,7 +412,7 @@ bool TerminalInput::HandleKey(const IInputEvent* const pInEvent) const
|
||||
// For Alt+Ctrl+Key messages, the UnicodeChar is NOT the Ctrl+key char, it's null.
|
||||
// So we need to get the char from the vKey.
|
||||
// EXCEPT for Alt+Ctrl+Space. Then the UnicodeChar is space, not NUL.
|
||||
wchar_t wchPressedChar = static_cast<wchar_t>(MapVirtualKeyW(keyEvent.GetVirtualKeyCode(), MAPVK_VK_TO_CHAR));
|
||||
auto wchPressedChar = static_cast<wchar_t>(MapVirtualKeyW(keyEvent.GetVirtualKeyCode(), MAPVK_VK_TO_CHAR));
|
||||
// This is a trick - C-Spc is supposed to send NUL. So quick change space -> @ (0x40)
|
||||
wchPressedChar = (wchPressedChar == UNICODE_SPACE) ? 0x40 : wchPressedChar;
|
||||
if (wchPressedChar >= 0x40 && wchPressedChar < 0x7F)
|
||||
|
||||
@ -21,16 +21,24 @@ namespace Microsoft::Console::VirtualTerminal
|
||||
{
|
||||
class TerminalInput final
|
||||
{
|
||||
|
||||
public:
|
||||
TerminalInput(_In_ std::function<void(std::deque<std::unique_ptr<IInputEvent>>&)> pfn);
|
||||
~TerminalInput();
|
||||
|
||||
TerminalInput() = delete;
|
||||
TerminalInput(const TerminalInput& old) = default;
|
||||
TerminalInput(TerminalInput&& moved) = default;
|
||||
|
||||
TerminalInput& operator=(const TerminalInput& old) = default;
|
||||
TerminalInput& operator=(TerminalInput&& moved) = default;
|
||||
|
||||
~TerminalInput() = default;
|
||||
|
||||
bool HandleKey(const IInputEvent* const pInEvent) const;
|
||||
void ChangeKeypadMode(const bool fApplicationMode);
|
||||
void ChangeCursorKeysMode(const bool fApplicationMode);
|
||||
|
||||
private:
|
||||
|
||||
std::function<void(std::deque<std::unique_ptr<IInputEvent>>&)> _pfnWriteEvents;
|
||||
bool _fKeypadApplicationMode = false;
|
||||
bool _fCursorApplicationMode = false;
|
||||
@ -60,7 +68,14 @@ namespace Microsoft::Console::VirtualTerminal
|
||||
// C++11 syntax for prohibiting assignment
|
||||
// We can't assign, everything here is const.
|
||||
// We also shouldn't need to, this is only for a specific table.
|
||||
_TermKeyMap(const _TermKeyMap&) = delete;
|
||||
_TermKeyMap& operator=(const _TermKeyMap&) = delete;
|
||||
|
||||
_TermKeyMap(_TermKeyMap&&) = delete;
|
||||
_TermKeyMap& operator=(_TermKeyMap&&) = delete;
|
||||
|
||||
_TermKeyMap() = delete;
|
||||
~_TermKeyMap() = default;
|
||||
};
|
||||
|
||||
static const _TermKeyMap s_rgCursorKeysNormalMapping[];
|
||||
@ -81,13 +96,13 @@ namespace Microsoft::Console::VirtualTerminal
|
||||
_In_reads_(cKeyMapping) const TerminalInput::_TermKeyMap* keyMapping,
|
||||
const size_t cKeyMapping,
|
||||
_Out_ const TerminalInput::_TermKeyMap** pMatchingMapping) const;
|
||||
|
||||
bool _TranslateDefaultMapping(const KeyEvent& keyEvent,
|
||||
_In_reads_(cKeyMapping) const TerminalInput::_TermKeyMap* keyMapping,
|
||||
const size_t cKeyMapping) const;
|
||||
|
||||
bool _SearchWithModifier(const KeyEvent& keyEvent) const;
|
||||
|
||||
|
||||
public:
|
||||
const size_t GetKeyMappingLength(const KeyEvent& keyEvent) const;
|
||||
const _TermKeyMap* GetKeyMapping(const KeyEvent& keyEvent) const;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user