2021-06-20 08:48:31 +12:00
|
|
|
/* Copyright 2021 Aristocratos (jakob@qvantnet.com)
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
2023-07-27 00:38:48 +12:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2021-06-20 08:48:31 +12:00
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
|
|
|
|
indent = tab
|
|
|
|
tab-size = 4
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
2021-07-04 11:18:48 +12:00
|
|
|
#include <atomic>
|
2021-07-23 11:41:00 +12:00
|
|
|
#include <array>
|
2023-12-25 14:26:13 +13:00
|
|
|
#include <unordered_map>
|
2021-08-04 09:47:46 +12:00
|
|
|
#include <deque>
|
2021-06-20 08:48:31 +12:00
|
|
|
|
2022-10-03 10:29:05 +13:00
|
|
|
using std::array;
|
|
|
|
using std::atomic;
|
|
|
|
using std::deque;
|
|
|
|
using std::string;
|
|
|
|
|
2023-09-21 19:40:18 +12:00
|
|
|
/* The input functions rely on the following termios parameters being set:
|
|
|
|
Non-canonical mode (c_lflags & ~(ICANON))
|
|
|
|
VMIN and VTIME (c_cc) set to 0
|
2021-06-20 08:48:31 +12:00
|
|
|
These will automatically be set when running Term::init() from btop_tools.cpp
|
|
|
|
*/
|
|
|
|
|
|
|
|
//* Functions and variables for handling keyboard and mouse input
|
|
|
|
namespace Input {
|
|
|
|
|
2021-07-23 11:41:00 +12:00
|
|
|
struct Mouse_loc {
|
2021-07-24 12:13:26 +12:00
|
|
|
int line, col, height, width;
|
2021-07-23 11:41:00 +12:00
|
|
|
};
|
|
|
|
|
2021-07-24 12:13:26 +12:00
|
|
|
//? line, col, height, width
|
2023-12-25 14:26:13 +13:00
|
|
|
extern std::unordered_map<string, Mouse_loc> mouse_mappings;
|
2021-07-23 11:41:00 +12:00
|
|
|
|
2023-09-21 19:40:18 +12:00
|
|
|
//* Signal mask used during polling read
|
|
|
|
extern sigset_t signal_mask;
|
|
|
|
|
2022-02-10 03:42:09 +13:00
|
|
|
extern atomic<bool> polling;
|
2021-07-23 11:41:00 +12:00
|
|
|
|
|
|
|
//* Mouse column and line position
|
|
|
|
extern array<int, 2> mouse_pos;
|
2021-07-04 11:18:48 +12:00
|
|
|
|
2021-06-20 08:48:31 +12:00
|
|
|
//* Last entered key
|
2021-08-04 09:47:46 +12:00
|
|
|
extern deque<string> history;
|
2021-06-20 08:48:31 +12:00
|
|
|
|
2024-01-14 15:26:02 +13:00
|
|
|
//* Poll keyboard & mouse input for <timeout> ms and return input availability as a bool
|
2023-09-21 19:40:18 +12:00
|
|
|
bool poll(const uint64_t timeout=0);
|
2021-06-20 08:48:31 +12:00
|
|
|
|
|
|
|
//* Get a key or mouse action from input
|
2021-07-23 11:41:00 +12:00
|
|
|
string get();
|
2021-06-20 08:48:31 +12:00
|
|
|
|
2021-06-26 09:58:19 +12:00
|
|
|
//* Wait until input is available and return key
|
2021-07-23 11:41:00 +12:00
|
|
|
string wait();
|
2021-06-20 08:48:31 +12:00
|
|
|
|
2023-09-21 19:40:18 +12:00
|
|
|
//* Interrupt poll/wait
|
|
|
|
void interrupt();
|
|
|
|
|
2021-06-20 08:48:31 +12:00
|
|
|
//* Clears last entered key
|
|
|
|
void clear();
|
|
|
|
|
2021-07-19 01:44:32 +12:00
|
|
|
//* Process actions for input <key>
|
2021-07-26 11:06:34 +12:00
|
|
|
void process(const string& key);
|
2021-07-19 01:44:32 +12:00
|
|
|
|
2022-10-03 10:29:05 +13:00
|
|
|
}
|