2020-07-11 12:45:21 +02:00
|
|
|
#ifndef TERMINAL_H
|
|
|
|
#define TERMINAL_H
|
|
|
|
|
|
|
|
#include <libtsm.h>
|
|
|
|
#include <Control.hpp>
|
|
|
|
#include <Font.hpp>
|
|
|
|
#include <Godot.hpp>
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
|
2020-07-11 14:14:25 +02:00
|
|
|
namespace godot
|
|
|
|
{
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2020-09-24 09:27:26 +02:00
|
|
|
class Terminal : public Control
|
2020-07-11 14:14:25 +02:00
|
|
|
{
|
2020-09-24 09:27:26 +02:00
|
|
|
GODOT_CLASS(Terminal, Control)
|
|
|
|
|
|
|
|
public:
|
|
|
|
struct cell
|
|
|
|
{
|
|
|
|
char ch[5];
|
|
|
|
struct tsm_screen_attr attr;
|
2020-11-10 04:04:08 +01:00
|
|
|
};
|
|
|
|
static const struct cell empty_cell;
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2020-09-24 09:27:26 +02:00
|
|
|
public:
|
|
|
|
typedef std::vector<std::vector<struct cell>> Cells;
|
|
|
|
typedef std::vector<struct cell> Row;
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2020-09-24 09:27:26 +02:00
|
|
|
Cells cells;
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2020-09-29 11:16:59 +02:00
|
|
|
Ref<InputEventKey> input_event_key;
|
|
|
|
|
2020-09-24 09:27:26 +02:00
|
|
|
protected:
|
|
|
|
tsm_screen *screen;
|
|
|
|
tsm_vte *vte;
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2020-09-24 09:27:26 +02:00
|
|
|
private:
|
|
|
|
static const uint8_t default_color_palette[TSM_COLOR_NUM][3];
|
2020-09-24 12:29:19 +02:00
|
|
|
static const std::map<std::pair<int64_t, int64_t>, uint32_t> keymap;
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2020-09-24 09:27:26 +02:00
|
|
|
Vector2 cell_size;
|
|
|
|
std::map<int, Color> palette = {};
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2020-09-24 09:27:26 +02:00
|
|
|
void update_size();
|
2020-07-11 14:14:25 +02:00
|
|
|
|
2020-09-24 09:27:26 +02:00
|
|
|
void update_color_palette();
|
|
|
|
std::pair<Color, Color> get_cell_colors(int row, int col);
|
|
|
|
void draw_background(int row, int col, Color bgcol);
|
|
|
|
void draw_foreground(int row, int col, Color fgcol);
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2020-09-24 09:27:26 +02:00
|
|
|
public:
|
|
|
|
static void _register_methods();
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2020-09-24 09:27:26 +02:00
|
|
|
Terminal();
|
|
|
|
~Terminal();
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2020-09-24 09:27:26 +02:00
|
|
|
void _init();
|
|
|
|
void _ready();
|
|
|
|
void _notification(int what);
|
2020-09-24 12:29:19 +02:00
|
|
|
void _gui_input(Variant event);
|
2020-09-24 09:27:26 +02:00
|
|
|
void _draw();
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2020-09-25 08:12:31 +02:00
|
|
|
void write(Variant data);
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2020-09-24 09:27:26 +02:00
|
|
|
int rows;
|
|
|
|
int cols;
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2020-09-24 09:27:26 +02:00
|
|
|
bool sleep;
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2020-09-24 09:27:26 +02:00
|
|
|
uint8_t color_palette[TSM_COLOR_NUM][3];
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2020-09-24 09:27:26 +02:00
|
|
|
tsm_age_t framebuffer_age;
|
|
|
|
};
|
2020-07-11 12:45:21 +02:00
|
|
|
} // namespace godot
|
|
|
|
|
|
|
|
#endif // TERMINAL_H
|