terml/source/terml_private.h

89 lines
2.0 KiB
C
Raw Permalink Normal View History

2023-12-25 16:26:13 +00:00
#ifndef TERML_TERML_PRIVATE_H
#define TERML_TERML_PRIVATE_H
#include "terml.h"
#define STRINGIFY2(x) #x
#define STRINGIFY(x) STRINGIFY2(x)
#define ESC "\x1B"
#define CSI "\x1B["
#define ALT_BUF() CSI "?1049h"
#define REG_BUF() CSI "?1049l"
#define CLEAR_SCREEN() CSI "2J"
#define HIDE_CURSOR() CSI "?25l"
#define SHOW_CURSOR() CSI "?25h"
2024-03-09 22:23:41 +00:00
#define SELECT_UTF8() CSI "%G"
2023-12-25 16:26:13 +00:00
#define REPORT_CUSROR_POSITION() CSI "6n"
#define CURSOR_POSITION_FORMAT() "%*1s[%u;%u"
#define CUP(x, y) CSI STRINGIFY(y) ";" STRINGIFY(x) "H"
#define FG(r, g, b) CSI "38;2;" STRINGIFY(r) ";" STRINGIFY(g) ";" STRINGIFY(b) "m"
#define BG(r, g, b) CSI "48;2;" STRINGIFY(r) ";" STRINGIFY(g) ";" STRINGIFY(b) "m"
2024-04-15 21:59:59 +00:00
struct tcelld
{
tcell cell;
bool dirty;
};
2023-12-25 16:26:13 +00:00
class terml
{
public:
terml();
virtual ~terml();
terml(const terml&) = delete;
terml(terml&&) = delete;
terml& operator=(const terml&) = delete;
terml& operator=(terml&&) = delete;
2024-05-03 14:15:35 +00:00
tcell get(unsigned int x, unsigned int y) const;
void set(unsigned int x, unsigned int y, tcell cell);
void flush() const;
2023-12-25 16:26:13 +00:00
void set_main_callback(terml_main_callback);
void set_quit_callback(terml_quit_callback);
void set_key_callback(terml_key_callback);
void set_resize_callback(terml_resize_callback);
2023-12-25 16:26:13 +00:00
void mainloop();
void stop();
unsigned int get_width() const;
unsigned int get_height() const;
void setup_buffer();
void set_console_settings();
void reset_console_settings();
2023-12-25 16:26:13 +00:00
protected:
virtual void set_console_settings_impl() = 0;
virtual void reset_console_settings_impl() = 0;
2023-12-25 16:26:13 +00:00
virtual void read_stdin(char* buffer, unsigned int buffer_size) = 0;
virtual unsigned long long timer() = 0;
virtual unsigned long long timer_frequency() = 0;
virtual void process_events() = 0;
void key_event(char code) const;
2023-12-25 16:26:13 +00:00
private:
2024-04-15 21:59:59 +00:00
tcelld* cells;
2023-12-25 16:26:13 +00:00
unsigned int width;
unsigned int height;
terml_main_callback main;
terml_quit_callback quit;
terml_key_callback key;
terml_resize_callback resize;
2023-12-25 16:26:13 +00:00
bool should_quit;
bool really_should_quit;
};
#endif//TERML_TERML_PRIVATE_H