34 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT) 35 #error "Only <final/final.h> can be included directly." 47 #include "final/ftypes.h" 48 #include "final/input/fkey_hashmap.h" 49 #include "final/input/fkey_map.h" 50 #include "final/util/char_ringbuffer.h" 51 #include "final/util/fstring.h" 70 : handler(std::move(fn))
74 inline void execute()
const 81 std::function<void()> handler{};
93 static constexpr std::size_t FIFO_BUF_SIZE{512};
114 auto getClassName()
const ->
FString;
116 auto getKey()
const noexcept -> FKey;
117 auto getKeyName (
const FKey)
const ->
FString;
118 auto getKeyBuffer() & noexcept ->
keybuffer&;
119 auto getKeyPressedTime()
const noexcept -> TimeValue;
120 static auto getKeypressTimeout() noexcept -> uInt64;
121 static auto getReadBlockingTime() noexcept -> uInt64;
124 template <
typename T>
125 void setTermcapMap (
const T&);
126 void setTermcapMap();
127 static void setKeypressTimeout (
const uInt64) noexcept;
128 static void setReadBlockingTime (
const uInt64) noexcept;
129 static void setNonBlockingInputSupport (
bool =
true) noexcept;
130 void setNonBlockingInput (
bool =
true);
131 void unsetNonBlockingInput() noexcept;
132 void enableUTF8() noexcept;
133 void disableUTF8() noexcept;
134 void enableMouseSequences() noexcept;
135 void disableMouseSequences() noexcept;
142 auto hasPendingInput()
const noexcept -> bool;
143 auto hasDataInQueue()
const -> bool;
146 auto hasUnprocessedInput()
const noexcept -> bool;
147 auto isKeyPressed (uInt64 = read_blocking_time) -> bool;
148 void clearKeyBuffer() noexcept;
149 void clearKeyBufferOnTimeout();
151 void escapeKeyHandling();
152 void processQueuedInput();
156 static constexpr FKey NOT_SET =
static_cast<FKey
>(-2);
157 static constexpr std::size_t MAX_QUEUE_SIZE = 32;
160 using FKeyMapPtr = std::shared_ptr<FKeyMap::KeyCapMapType>;
161 using KeyMapEnd = FKeyMap::KeyCapMapType::const_iterator;
165 auto getMouseProtocolKey()
const -> FKey;
166 auto getTermcapKey() -> FKey;
167 auto getKnownKey() -> FKey;
168 auto getSingleKey() -> FKey;
171 static auto isKeypressTimeout() -> bool;
172 static auto isIntervalTimeout() -> bool;
175 auto UTF8decode (
const std::size_t)
const noexcept -> FKey;
176 auto readKey() -> ssize_t;
177 void parseKeyBuffer();
178 auto parseKeyString() -> FKey;
179 auto keyCorrection (
const FKey&)
const -> FKey;
180 void substringKeyHandling();
181 void keyPressedCommand()
const;
182 void keyReleasedCommand()
const;
183 void escapeKeyPressedCommand()
const;
184 void mouseTrackingCommand()
const;
192 static TimeValue time_keypressed;
193 static uInt64 read_blocking_time;
194 static uInt64 read_blocking_time_short;
195 static uInt64 key_timeout;
196 static bool non_blocking_input_support;
197 FKeyMapPtr key_cap_ptr{};
198 KeyMapEnd key_cap_end{};
201 FKey fkey{FKey::None};
202 FKey key{FKey::None};
203 int stdin_status_flags{0};
204 char read_character{};
205 bool has_pending_input{
false};
206 bool fifo_in_use{
false};
207 bool utf8_input{
false};
208 bool mouse_support{
true};
209 bool non_blocking_stdin{
false};
214 inline auto FKeyboard::getClassName()
const ->
FString 215 {
return "FKeyboard"; }
218 inline auto FKeyboard::getKey()
const noexcept -> FKey
222 inline auto FKeyboard::getKeyBuffer() & noexcept ->
keybuffer&
226 inline auto FKeyboard::getKeyPressedTime()
const noexcept -> TimeValue
227 {
return time_keypressed; }
230 inline auto FKeyboard::getKeypressTimeout() noexcept -> uInt64
231 {
return key_timeout; }
234 inline auto FKeyboard::getReadBlockingTime() noexcept -> uInt64
235 {
return read_blocking_time; }
238 template <
typename T>
239 inline void FKeyboard::setTermcapMap (
const T& keymap)
241 key_cap_ptr = std::make_shared<T>(keymap);
242 key_cap_end = key_cap_ptr->cend();
243 fkeyhashmap::setKeyCapMap<keybuffer>(key_cap_ptr->cbegin(), key_cap_end);
247 inline void FKeyboard::setTermcapMap()
249 using type = FKeyMap::KeyCapMapType;
250 key_cap_ptr = std::make_shared<type>(FKeyMap::getKeyCapMap());
252 key_cap_end = std::find_if ( key_cap_ptr->cbegin()
253 , key_cap_ptr->cend()
255 {
return entry.length == 0; }
257 fkeyhashmap::setKeyCapMap<keybuffer>(key_cap_ptr->cbegin(), key_cap_end);
261 inline void FKeyboard::setKeypressTimeout (
const uInt64 timeout) noexcept
262 { key_timeout = timeout; }
265 inline void FKeyboard::setReadBlockingTime (
const uInt64 blocking_time) noexcept
266 { read_blocking_time = blocking_time; }
269 inline void FKeyboard::setNonBlockingInputSupport (
bool enable) noexcept
270 { non_blocking_input_support = enable; }
273 inline void FKeyboard::unsetNonBlockingInput() noexcept
274 { setNonBlockingInput(
false); }
277 inline auto FKeyboard::hasPendingInput()
const noexcept ->
bool 278 {
return has_pending_input; }
281 inline auto FKeyboard::hasDataInQueue()
const ->
bool 282 {
return ! fkey_queue.isEmpty(); }
285 inline void FKeyboard::enableUTF8() noexcept
286 { utf8_input =
true; }
289 inline void FKeyboard::disableUTF8() noexcept
290 { utf8_input =
false; }
293 inline void FKeyboard::enableMouseSequences() noexcept
294 { mouse_support =
true; }
297 inline void FKeyboard::disableMouseSequences() noexcept
298 { mouse_support =
false; }
302 { keypressed_cmd = cmd; }
306 { keyreleased_cmd = cmd; }
310 { escape_key_cmd = cmd; }
313 inline void FKeyboard::setMouseTrackingCommand (
const FKeyboardCommand& cmd)
314 { mouse_tracking_cmd = cmd; }
318 #endif // FKEYBOARD_H Definition: fkeyboard.h:89
Definition: fkeyboard.h:64
Definition: fkey_map.h:44
Definition: class_template.cpp:25