2022-12-29 10:52:13 +01:00
|
|
|
// SPDX-FileCopyrightText: 2021-2022 Leroy Hopson <godot-xterm@leroy.geek.nz>
|
|
|
|
// SPDX-License-Identifier: MIT
|
2021-07-02 19:04:34 +02:00
|
|
|
|
2020-07-11 12:45:21 +02:00
|
|
|
#ifndef TERMINAL_H
|
|
|
|
#define TERMINAL_H
|
|
|
|
|
2022-12-29 10:52:13 +01:00
|
|
|
#include <godot_cpp/classes/control.hpp>
|
|
|
|
#include <godot_cpp/classes/font.hpp>
|
|
|
|
#include <godot_cpp/classes/input_event_key.hpp>
|
|
|
|
#include <godot_cpp/variant/packed_byte_array.hpp>
|
2021-06-06 14:58:50 +02:00
|
|
|
#include <libtsm.h>
|
2020-07-11 12:45:21 +02:00
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
|
2021-06-06 14:58:50 +02:00
|
|
|
namespace godot {
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2021-06-06 14:58:50 +02:00
|
|
|
class Terminal : public Control {
|
2022-12-29 10:52:13 +01:00
|
|
|
GDCLASS(Terminal, Control)
|
2020-09-24 09:27:26 +02:00
|
|
|
|
2021-06-06 14:58:50 +02:00
|
|
|
public:
|
|
|
|
Ref<InputEventKey> input_event_key;
|
2020-09-29 11:16:59 +02:00
|
|
|
|
2021-06-06 14:58:50 +02:00
|
|
|
protected:
|
2022-12-29 10:52:13 +01:00
|
|
|
static void _bind_methods();
|
|
|
|
|
2021-06-06 14:58:50 +02:00
|
|
|
tsm_screen *screen;
|
|
|
|
tsm_vte *vte;
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2021-06-06 14:58:50 +02:00
|
|
|
private:
|
|
|
|
static const uint8_t default_color_palette[TSM_COLOR_NUM][3];
|
2021-06-06 14:37:07 +02:00
|
|
|
|
|
|
|
static std::map<std::pair<int64_t, int64_t>, int> _key_list;
|
|
|
|
static void _populate_key_list();
|
|
|
|
static uint32_t mapkey(std::pair<int64_t, int64_t> key);
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2021-06-06 14:58:50 +02:00
|
|
|
std::map<int, Color> palette = {};
|
|
|
|
std::map<String, Ref<Font>> fontmap = {};
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2021-06-06 14:58:50 +02:00
|
|
|
void update_size();
|
|
|
|
void update_theme();
|
2021-06-19 15:57:05 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
std::pair<Color, Color> get_cell_colors(const tsm_screen_attr *attr);
|
2021-07-12 17:24:21 +02:00
|
|
|
void draw_background(int row, int col, Color bgcol, int width);
|
2021-06-19 15:57:05 +02:00
|
|
|
void draw_foreground(int row, int col, char *ch, const tsm_screen_attr *attr,
|
|
|
|
Color fgcol);
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2021-06-06 14:58:50 +02:00
|
|
|
public:
|
|
|
|
Terminal();
|
|
|
|
~Terminal();
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2021-06-06 14:58:50 +02:00
|
|
|
void _ready();
|
|
|
|
void _notification(int what);
|
|
|
|
void _gui_input(Variant event);
|
|
|
|
void _draw();
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2022-12-29 10:52:13 +01:00
|
|
|
void write(PackedByteArray data);
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2021-07-08 15:10:34 +02:00
|
|
|
void sb_up(int num);
|
|
|
|
void sb_down(int num);
|
2021-07-13 01:27:20 +02:00
|
|
|
void sb_reset();
|
|
|
|
void clear_sb();
|
2021-07-08 15:10:34 +02:00
|
|
|
|
2021-07-08 15:10:58 +02:00
|
|
|
void start_selection(Vector2 position);
|
|
|
|
void select_to_pointer(Vector2 position);
|
|
|
|
void reset_selection();
|
2021-07-08 15:33:46 +02:00
|
|
|
String copy_selection();
|
2021-07-13 17:20:29 +02:00
|
|
|
String copy_all();
|
2021-07-08 15:10:58 +02:00
|
|
|
|
2021-06-19 15:57:05 +02:00
|
|
|
enum UpdateMode {
|
|
|
|
DISABLED,
|
|
|
|
AUTO,
|
|
|
|
ALL,
|
|
|
|
ALL_NEXT_FRAME,
|
|
|
|
};
|
2022-12-29 10:52:13 +01:00
|
|
|
int update_mode = UpdateMode::AUTO;
|
|
|
|
int get_update_mode();
|
|
|
|
void set_update_mode(int update_mode);
|
|
|
|
|
|
|
|
Vector2 cell_size = Vector2(0, 0);
|
|
|
|
Vector2 get_cell_size();
|
|
|
|
int rows = 24;
|
|
|
|
int get_rows();
|
|
|
|
int cols = 80;
|
|
|
|
int get_cols();
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2021-06-06 14:58:50 +02:00
|
|
|
uint8_t color_palette[TSM_COLOR_NUM][3];
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2021-06-06 14:58:50 +02:00
|
|
|
tsm_age_t framebuffer_age;
|
|
|
|
};
|
2020-07-11 12:45:21 +02:00
|
|
|
} // namespace godot
|
|
|
|
|
2020-11-29 09:22:34 +01:00
|
|
|
#endif // TERMINAL_H
|