| 1 |
// Copyright (c) 2011-2015 Ryan Prichard |
| 2 |
// |
| 3 |
// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 4 |
// of this software and associated documentation files (the "Software"), to |
| 5 |
// deal in the Software without restriction, including without limitation the |
| 6 |
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 7 |
// sell copies of the Software, and to permit persons to whom the Software is |
| 8 |
// furnished to do so, subject to the following conditions: |
| 9 |
// |
| 10 |
// The above copyright notice and this permission notice shall be included in |
| 11 |
// all copies or substantial portions of the Software. |
| 12 |
// |
| 13 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 |
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 |
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 18 |
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 19 |
// IN THE SOFTWARE. |
| 20 |
|
| 21 |
#ifndef CONSOLEINPUT_H |
| 22 |
#define CONSOLEINPUT_H |
| 23 |
|
| 24 |
#include <windows.h> |
| 25 |
#include <stdint.h> |
| 26 |
|
| 27 |
#include <memory> |
| 28 |
#include <string> |
| 29 |
#include <vector> |
| 30 |
|
| 31 |
#include "Coord.h" |
| 32 |
#include "InputMap.h" |
| 33 |
#include "SmallRect.h" |
| 34 |
|
| 35 |
class Win32Console; |
| 36 |
class DsrSender; |
| 37 |
|
| 38 |
class ConsoleInput |
| 39 |
{ |
| 40 |
public: |
| 41 |
ConsoleInput(HANDLE conin, int mouseMode, DsrSender &dsrSender, |
| 42 |
Win32Console &console); |
| 43 |
void writeInput(const std::string &input); |
| 44 |
void flushIncompleteEscapeCode(); |
| 45 |
void setMouseWindowRect(SmallRect val) { m_mouseWindowRect = val; } |
| 46 |
void updateInputFlags(bool forceTrace=false); |
| 47 |
bool shouldActivateTerminalMouse(); |
| 48 |
|
| 49 |
private: |
| 50 |
void doWrite(bool isEof); |
| 51 |
void flushInputRecords(std::vector<INPUT_RECORD> &records); |
| 52 |
int scanInput(std::vector<INPUT_RECORD> &records, |
| 53 |
const char *input, |
| 54 |
int inputSize, |
| 55 |
bool isEof); |
| 56 |
int scanMouseInput(std::vector<INPUT_RECORD> &records, |
| 57 |
const char *input, |
| 58 |
int inputSize); |
| 59 |
void appendUtf8Char(std::vector<INPUT_RECORD> &records, |
| 60 |
const char *charBuffer, |
| 61 |
int charLen, |
| 62 |
bool terminalAltEscape); |
| 63 |
void appendKeyPress(std::vector<INPUT_RECORD> &records, |
| 64 |
uint16_t virtualKey, |
| 65 |
uint32_t winCodePointDn, |
| 66 |
uint32_t winCodePointUp, |
| 67 |
uint16_t winKeyState, |
| 68 |
uint32_t vtCodePoint, |
| 69 |
uint16_t vtKeyState); |
| 70 |
|
| 71 |
public: |
| 72 |
static void appendCPInputRecords(std::vector<INPUT_RECORD> &records, |
| 73 |
BOOL keyDown, |
| 74 |
uint16_t virtualKey, |
| 75 |
uint32_t codePoint, |
| 76 |
uint16_t keyState); |
| 77 |
static void appendInputRecord(std::vector<INPUT_RECORD> &records, |
| 78 |
BOOL keyDown, |
| 79 |
uint16_t virtualKey, |
| 80 |
wchar_t utf16Char, |
| 81 |
uint16_t keyState); |
| 82 |
|
| 83 |
private: |
| 84 |
DWORD inputConsoleMode(); |
| 85 |
|
| 86 |
private: |
| 87 |
Win32Console &m_console; |
| 88 |
HANDLE m_conin = nullptr; |
| 89 |
int m_mouseMode = 0; |
| 90 |
DsrSender &m_dsrSender; |
| 91 |
bool m_dsrSent = false; |
| 92 |
std::string m_byteQueue; |
| 93 |
InputMap m_inputMap; |
| 94 |
DWORD m_lastWriteTick = 0; |
| 95 |
DWORD m_mouseButtonState = 0; |
| 96 |
struct DoubleClickDetection { |
| 97 |
DWORD button = 0; |
| 98 |
Coord pos; |
| 99 |
DWORD tick = 0; |
| 100 |
bool released = false; |
| 101 |
} m_doubleClick; |
| 102 |
bool m_enableExtendedEnabled = false; |
| 103 |
bool m_mouseInputEnabled = false; |
| 104 |
bool m_quickEditEnabled = false; |
| 105 |
bool m_escapeInputEnabled = false; |
| 106 |
SmallRect m_mouseWindowRect; |
| 107 |
}; |
| 108 |
|
| 109 |
#endif // CONSOLEINPUT_H |