2020-11-28 14:40:46 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-11-22 15:17:14 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <termpaintx.h>
|
|
|
|
#define EV_TIMEOUT 0xffff
|
2020-11-22 17:09:17 +00:00
|
|
|
#define EV_IGNORE 0xfffe
|
2020-12-02 22:06:42 +00:00
|
|
|
#define EV_RESIZE 0xfffd
|
2020-11-22 15:17:14 +00:00
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <optional>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
struct Event {
|
|
|
|
int type;
|
|
|
|
int modifier;
|
|
|
|
std::string string;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class Align {
|
|
|
|
HCenter = 0x01,
|
|
|
|
Left = 0x02,
|
|
|
|
Right = 0x04,
|
|
|
|
|
|
|
|
VCenter = 0x10,
|
|
|
|
Top = 0x20,
|
|
|
|
Bottom = 0x40,
|
|
|
|
|
|
|
|
Center = HCenter | VCenter,
|
|
|
|
};
|
2020-11-22 19:34:48 +00:00
|
|
|
Align operator|(const Align &a, const Align &b);
|
2020-11-22 15:17:14 +00:00
|
|
|
|
|
|
|
extern termpaint_surface *surface;
|
|
|
|
|
|
|
|
enum AttributeSetType {
|
|
|
|
ASNormal,
|
|
|
|
ASWatched,
|
|
|
|
ASUnwatched,
|
|
|
|
ASetTypeCount,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct AttributeSet {
|
|
|
|
termpaint_attr *normal;
|
|
|
|
termpaint_attr *highlight;
|
|
|
|
};
|
|
|
|
extern AttributeSet attributes[ASetTypeCount];
|
|
|
|
|
|
|
|
enum class Button {
|
|
|
|
Ok = (1<<0),
|
|
|
|
Cancel = (1<<1),
|
|
|
|
Yes = (1<<2),
|
|
|
|
No = (1<<3),
|
|
|
|
};
|
2020-11-22 19:34:48 +00:00
|
|
|
Button operator|(const Button &a, const Button &b);
|
|
|
|
Button operator&(const Button &a, const Button &b);
|
2020-11-22 15:17:14 +00:00
|
|
|
|
2020-11-22 19:34:48 +00:00
|
|
|
void tp_init();
|
2020-12-16 18:37:46 +00:00
|
|
|
void tp_init_from_fd(int fd);
|
2020-11-22 19:34:48 +00:00
|
|
|
void tp_shutdown();
|
2020-11-26 12:25:25 +00:00
|
|
|
void tp_flush(const bool force=false);
|
2020-11-22 19:34:48 +00:00
|
|
|
void tp_pause();
|
|
|
|
void tp_unpause();
|
2020-12-02 22:06:42 +00:00
|
|
|
std::optional<Event> tp_wait_for_event(int timeout=0);
|
2020-11-22 15:17:14 +00:00
|
|
|
|
2020-11-22 17:09:17 +00:00
|
|
|
struct action
|
|
|
|
{
|
|
|
|
int type;
|
|
|
|
std::string string;
|
|
|
|
int modifier;
|
|
|
|
|
|
|
|
std::function<void(void)> func;
|
|
|
|
std::string help;
|
|
|
|
};
|
2020-11-22 19:34:48 +00:00
|
|
|
bool tui_handle_action(const Event &event, const std::vector<action> &actions);
|
2020-11-22 17:09:17 +00:00
|
|
|
|
2020-11-22 19:34:48 +00:00
|
|
|
size_t string_width(const std::string &str);
|
|
|
|
std::pair<size_t, size_t> string_size(const std::string &str);
|
|
|
|
void write_multiline_string(const int x, const int y, const std::string &str, termpaint_attr *attr);
|
2020-11-26 23:32:10 +00:00
|
|
|
std::string text_wrap(const std::string &text, const size_t desired_width);
|
2020-11-22 15:17:14 +00:00
|
|
|
|
2020-11-22 19:34:48 +00:00
|
|
|
Button message_box(const std::string &caption, const std::string &text, const Button buttons=Button::Ok, const Button default_button=Button::Ok, const Align align=Align::Center);
|
2021-07-18 14:11:16 +00:00
|
|
|
void draw_box_with_caption(int x, int y, int w, int h, const std::string &caption=std::string());
|
2020-11-22 19:34:48 +00:00
|
|
|
int get_selection(const std::string &caption, const std::vector<std::string> &choices, size_t selected=0, const Align align=Align::Center);
|
2021-07-18 21:27:20 +00:00
|
|
|
std::string edit_string(const std::string &caption, const std::string &text, const std::string &value, const Align align=Align::Center);
|
2020-11-22 19:34:48 +00:00
|
|
|
std::string get_string(const std::string &caption, const std::string &text=std::string(), const Align align=Align::Center);
|
2020-11-22 15:17:14 +00:00
|
|
|
|
|
|
|
struct progress_info;
|
2020-11-22 19:34:48 +00:00
|
|
|
progress_info* begin_progress(const std::string &caption, const int width, const Align align=Align::Center);
|
|
|
|
void update_progress(progress_info *info, const int val, const int maxval);
|
|
|
|
void end_progress(progress_info *info);
|
2020-11-22 15:17:14 +00:00
|
|
|
|
2021-07-18 14:41:19 +00:00
|
|
|
void tui_abort(const std::string &message);
|
2020-11-22 19:34:48 +00:00
|
|
|
void tui_abort(const char *fmt, ...);
|