2020-09-02 10:55:56 +03:00
|
|
|
#ifndef __LIB__TERM_H__
|
|
|
|
#define __LIB__TERM_H__
|
|
|
|
|
|
|
|
#include <stddef.h>
|
2021-08-16 19:02:28 +03:00
|
|
|
#include <stdint.h>
|
2020-09-02 10:55:56 +03:00
|
|
|
#include <stdbool.h>
|
2020-09-22 01:18:13 +03:00
|
|
|
#include <lib/image.h>
|
2022-02-07 04:10:57 +03:00
|
|
|
#include <lib/print.h>
|
2020-09-02 10:55:56 +03:00
|
|
|
|
2021-08-16 19:02:28 +03:00
|
|
|
#define TERM_TABSIZE (8)
|
|
|
|
#define MAX_ESC_VALUES (16)
|
|
|
|
|
|
|
|
extern struct term_context {
|
|
|
|
bool control_sequence;
|
|
|
|
bool csi;
|
|
|
|
bool escape;
|
|
|
|
bool rrr;
|
|
|
|
bool discard_next;
|
|
|
|
bool bold;
|
|
|
|
bool reverse_video;
|
|
|
|
bool dec_private;
|
|
|
|
bool insert_mode;
|
|
|
|
uint8_t g_select;
|
|
|
|
uint8_t charsets[2];
|
|
|
|
size_t current_charset;
|
|
|
|
size_t escape_offset;
|
|
|
|
size_t esc_values_i;
|
|
|
|
size_t saved_cursor_x;
|
|
|
|
size_t saved_cursor_y;
|
|
|
|
size_t current_primary;
|
|
|
|
size_t scroll_top_margin;
|
|
|
|
size_t scroll_bottom_margin;
|
|
|
|
uint32_t esc_values[MAX_ESC_VALUES];
|
2022-01-19 01:46:25 +03:00
|
|
|
|
|
|
|
bool saved_state_bold;
|
|
|
|
bool saved_state_reverse_video;
|
|
|
|
size_t saved_state_current_charset;
|
|
|
|
size_t saved_state_current_primary;
|
2021-08-16 19:02:28 +03:00
|
|
|
} term_context;
|
|
|
|
|
|
|
|
enum {
|
2022-09-17 11:40:14 +03:00
|
|
|
_NOT_READY,
|
2021-08-16 19:02:28 +03:00
|
|
|
VBE,
|
2021-12-14 08:47:28 +03:00
|
|
|
TEXTMODE,
|
|
|
|
FALLBACK
|
2021-08-16 19:02:28 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
extern int current_video_mode;
|
|
|
|
extern int term_backend;
|
|
|
|
extern size_t term_rows, term_cols;
|
|
|
|
extern bool term_runtime;
|
|
|
|
|
2022-09-20 10:54:35 +03:00
|
|
|
void term_notready(void);
|
2022-01-05 18:03:26 +03:00
|
|
|
void term_fallback(void);
|
|
|
|
|
2021-08-16 19:02:28 +03:00
|
|
|
void term_reinit(void);
|
|
|
|
void term_deinit(void);
|
2022-08-14 16:09:57 +03:00
|
|
|
void term_vbe(char *config, size_t width, size_t height);
|
2021-08-16 19:02:28 +03:00
|
|
|
void term_textmode(void);
|
|
|
|
void term_write(uint64_t buf, uint64_t count);
|
|
|
|
|
2020-12-07 19:14:14 +03:00
|
|
|
extern void (*raw_putchar)(uint8_t c);
|
2020-09-02 10:55:56 +03:00
|
|
|
extern void (*clear)(bool move);
|
|
|
|
extern void (*enable_cursor)(void);
|
2021-06-08 01:06:33 +03:00
|
|
|
extern bool (*disable_cursor)(void);
|
2021-08-16 19:02:28 +03:00
|
|
|
extern void (*set_cursor_pos)(size_t x, size_t y);
|
|
|
|
extern void (*get_cursor_pos)(size_t *x, size_t *y);
|
|
|
|
extern void (*set_text_fg)(size_t fg);
|
|
|
|
extern void (*set_text_bg)(size_t bg);
|
|
|
|
extern void (*set_text_fg_bright)(size_t fg);
|
|
|
|
extern void (*set_text_bg_bright)(size_t bg);
|
2022-09-04 07:39:13 +03:00
|
|
|
extern void (*set_text_fg_rgb)(uint32_t fg);
|
|
|
|
extern void (*set_text_bg_rgb)(uint32_t bg);
|
2021-08-01 00:51:48 +03:00
|
|
|
extern void (*set_text_fg_default)(void);
|
|
|
|
extern void (*set_text_bg_default)(void);
|
2021-07-08 17:33:24 +03:00
|
|
|
extern bool (*scroll_disable)(void);
|
|
|
|
extern void (*scroll_enable)(void);
|
2021-08-16 19:02:28 +03:00
|
|
|
extern void (*term_move_character)(size_t new_x, size_t new_y, size_t old_x, size_t old_y);
|
|
|
|
extern void (*term_scroll)(void);
|
2022-01-19 01:46:25 +03:00
|
|
|
extern void (*term_revscroll)(void);
|
2021-08-16 19:02:28 +03:00
|
|
|
extern void (*term_swap_palette)(void);
|
2022-01-19 01:46:25 +03:00
|
|
|
extern void (*term_save_state)(void);
|
|
|
|
extern void (*term_restore_state)(void);
|
2020-09-02 10:55:56 +03:00
|
|
|
|
2020-11-20 21:55:18 +03:00
|
|
|
extern void (*term_double_buffer_flush)(void);
|
|
|
|
|
2021-08-16 19:02:28 +03:00
|
|
|
extern uint64_t (*term_context_size)(void);
|
|
|
|
extern void (*term_context_save)(uint64_t ptr);
|
|
|
|
extern void (*term_context_restore)(uint64_t ptr);
|
2021-08-16 21:56:39 +03:00
|
|
|
extern void (*term_full_refresh)(void);
|
2020-09-02 10:55:56 +03:00
|
|
|
|
2021-08-16 19:02:28 +03:00
|
|
|
#define TERM_CB_DEC 10
|
|
|
|
#define TERM_CB_BELL 20
|
|
|
|
#define TERM_CB_PRIVATE_ID 30
|
2021-08-16 20:32:09 +03:00
|
|
|
#define TERM_CB_STATUS_REPORT 40
|
2021-08-16 23:47:40 +03:00
|
|
|
#define TERM_CB_POS_REPORT 50
|
|
|
|
#define TERM_CB_KBD_LEDS 60
|
|
|
|
#define TERM_CB_MODE 70
|
|
|
|
#define TERM_CB_LINUX 80
|
2021-04-04 19:05:18 +03:00
|
|
|
|
2021-08-16 19:02:28 +03:00
|
|
|
#define TERM_CTX_SIZE ((uint64_t)(-1))
|
|
|
|
#define TERM_CTX_SAVE ((uint64_t)(-2))
|
|
|
|
#define TERM_CTX_RESTORE ((uint64_t)(-3))
|
2021-08-16 21:56:39 +03:00
|
|
|
#define TERM_FULL_REFRESH ((uint64_t)(-4))
|
2020-10-27 10:09:27 +03:00
|
|
|
|
2022-04-01 11:00:36 +03:00
|
|
|
extern uint64_t term_arg;
|
|
|
|
extern void (*term_callback)(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t);
|
2021-04-11 03:30:48 +03:00
|
|
|
|
2021-10-09 14:32:57 +03:00
|
|
|
extern bool term_autoflush;
|
|
|
|
|
|
|
|
inline void reset_term(void) {
|
2021-11-20 23:47:51 +03:00
|
|
|
term_autoflush = true;
|
|
|
|
enable_cursor();
|
2022-02-07 04:10:57 +03:00
|
|
|
print("\e[2J\e[H");
|
2021-11-20 23:47:51 +03:00
|
|
|
term_double_buffer_flush();
|
2021-10-09 14:32:57 +03:00
|
|
|
}
|
|
|
|
|
2022-02-07 04:10:57 +03:00
|
|
|
inline void set_cursor_pos_helper(size_t x, size_t y) {
|
|
|
|
print("\e[%u;%uH", (int)y + 1, (int)x + 1);
|
|
|
|
}
|
|
|
|
|
2020-09-02 10:55:56 +03:00
|
|
|
#endif
|