2021-06-19 22:48:31 +02: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-26 14:38:48 +02:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2021-06-19 22:48:31 +02: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 01:18:48 +02:00
|
|
|
#include <atomic>
|
2021-07-23 01:41:00 +02:00
|
|
|
#include <array>
|
|
|
|
#include <robin_hood.h>
|
2021-08-03 23:47:46 +02:00
|
|
|
#include <deque>
|
2021-06-19 22:48:31 +02:00
|
|
|
|
2022-10-02 23:29:05 +02:00
|
|
|
using robin_hood::unordered_flat_map;
|
|
|
|
using std::array;
|
|
|
|
using std::atomic;
|
|
|
|
using std::deque;
|
|
|
|
using std::string;
|
|
|
|
|
2021-06-19 22:48:31 +02:00
|
|
|
/* The input functions relies on the following std::cin options being set:
|
|
|
|
cin.sync_with_stdio(false);
|
|
|
|
cin.tie(NULL);
|
|
|
|
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 01:41:00 +02:00
|
|
|
struct Mouse_loc {
|
2021-07-24 02:13:26 +02:00
|
|
|
int line, col, height, width;
|
2021-07-23 01:41:00 +02:00
|
|
|
};
|
|
|
|
|
2021-07-24 02:13:26 +02:00
|
|
|
//? line, col, height, width
|
2021-07-23 01:41:00 +02:00
|
|
|
extern unordered_flat_map<string, Mouse_loc> mouse_mappings;
|
|
|
|
|
|
|
|
extern atomic<bool> interrupt;
|
2022-02-09 15:42:09 +01:00
|
|
|
extern atomic<bool> polling;
|
2021-07-23 01:41:00 +02:00
|
|
|
|
|
|
|
//* Mouse column and line position
|
|
|
|
extern array<int, 2> mouse_pos;
|
2021-07-04 01:18:48 +02:00
|
|
|
|
2021-06-19 22:48:31 +02:00
|
|
|
//* Last entered key
|
2021-08-03 23:47:46 +02:00
|
|
|
extern deque<string> history;
|
2021-06-19 22:48:31 +02:00
|
|
|
|
|
|
|
//* Poll keyboard & mouse input for <timeout> ms and return input availabilty as a bool
|
|
|
|
bool poll(int timeout=0);
|
|
|
|
|
|
|
|
//* Get a key or mouse action from input
|
2021-07-23 01:41:00 +02:00
|
|
|
string get();
|
2021-06-19 22:48:31 +02:00
|
|
|
|
2021-06-25 23:58:19 +02:00
|
|
|
//* Wait until input is available and return key
|
2021-07-23 01:41:00 +02:00
|
|
|
string wait();
|
2021-06-19 22:48:31 +02:00
|
|
|
|
|
|
|
//* Clears last entered key
|
|
|
|
void clear();
|
|
|
|
|
2021-07-18 15:44:32 +02:00
|
|
|
//* Process actions for input <key>
|
2021-07-26 01:06:34 +02:00
|
|
|
void process(const string& key);
|
2021-07-18 15:44:32 +02:00
|
|
|
|
2022-10-02 23:29:05 +02:00
|
|
|
}
|