- Notifications
You must be signed in to change notification settings - Fork 8.5k
/
Copy pathinputBuffer.hpp
106 lines (87 loc) · 3.71 KB
/
inputBuffer.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#pragma once
#include"readData.hpp"
#include"../types/inc/IInputEvent.hpp"
#include"../server/ObjectHandle.h"
#include"../server/ObjectHeader.h"
#include"../terminal/input/terminalInput.hpp"
#include<deque>
namespaceMicrosoft::Console::Render
{
classRenderer;
}
classInputBufferfinal : public ConsoleObjectHeader
{
public:
DWORD InputMode;
ConsoleWaitQueue WaitQueue; // formerly ReadWaitQueue
InputBuffer();
// String oriented APIs
voidConsume(bool isUnicode, std::wstring_view& source, std::span<char>& target);
voidConsumeCached(bool isUnicode, std::span<char>& target);
voidCache(std::wstring_view source);
// INPUT_RECORD oriented APIs
size_tConsumeCached(bool isUnicode, size_t count, InputEventQueue& target);
size_tPeekCached(bool isUnicode, size_t count, InputEventQueue& target);
voidCache(bool isUnicode, InputEventQueue& source, size_t expectedSourceSize);
// storage API for partial dbcs bytes being written to the buffer
boolIsWritePartialByteSequenceAvailable() constnoexcept;
const INPUT_RECORD& FetchWritePartialByteSequence() noexcept;
voidStoreWritePartialByteSequence(const INPUT_RECORD& event) noexcept;
voidReinitializeInputBuffer();
voidWakeUpReadersWaitingForData();
voidTerminateRead(_In_ WaitTerminationReason Flag);
size_tGetNumberOfReadyEvents() constnoexcept;
voidFlush();
voidFlushAllButKeys();
[[nodiscard]] NTSTATUS Read(_Out_ InputEventQueue& OutEvents,
constsize_t AmountToRead,
constbool Peek,
constbool WaitForData,
constbool Unicode,
constbool Stream);
size_tPrepend(const std::span<const INPUT_RECORD>& inEvents);
size_tWrite(const INPUT_RECORD& inEvent);
size_tWrite(const std::span<const INPUT_RECORD>& inEvents);
voidWriteString(const std::wstring_view& text);
voidWriteFocusEvent(bool focused) noexcept;
boolWriteMouseEvent(til::point position, unsignedint button, short keyState, short wheelDelta);
boolIsInVirtualTerminalInputMode() const;
Microsoft::Console::VirtualTerminal::TerminalInput& GetTerminalInput();
private:
enumclassReadingMode : uint8_t
{
StringA,
StringW,
InputEventsA,
InputEventsW,
};
std::string _cachedTextA;
std::string_view _cachedTextReaderA;
std::wstring _cachedTextW;
std::wstring_view _cachedTextReaderW;
std::deque<INPUT_RECORD> _cachedInputEvents;
ReadingMode _readingMode = ReadingMode::StringA;
std::deque<INPUT_RECORD> _storage;
INPUT_RECORD _writePartialByteSequence{};
bool _writePartialByteSequenceAvailable = false;
Microsoft::Console::VirtualTerminal::TerminalInput _termInput;
// Wakes up readers waiting for data to be in the input buffer.
auto_wakeupReadersOnExit() noexcept
{
constauto initiallyEmpty = _storage.empty();
returnwil::scope_exit([this, initiallyEmpty]() {
_wakeupReadersImpl(initiallyEmpty);
});
}
void_wakeupReadersImpl(bool initiallyEmpty);
void_switchReadingMode(ReadingMode mode);
void_switchReadingModeSlowPath(ReadingMode mode);
void_WriteBuffer(const std::span<const INPUT_RECORD>& inRecords, _Out_ size_t& eventsWritten);
bool_CoalesceEvent(const INPUT_RECORD& inEvent) noexcept;
void_writeString(const std::wstring_view& text);
#ifdef UNIT_TESTING
friendclassInputBufferTests;
#endif
};