rulimine/common/lib/term.h

126 lines
3.3 KiB
C
Raw Normal View History

2020-09-02 10:55:56 +03:00
#ifndef __LIB__TERM_H__
#define __LIB__TERM_H__
#include <stddef.h>
#include <stdint.h>
2020-09-02 10:55:56 +03:00
#include <stdbool.h>
#include <lib/image.h>
#include <lib/print.h>
2020-09-02 10:55:56 +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];
bool saved_state_bold;
bool saved_state_reverse_video;
size_t saved_state_current_charset;
size_t saved_state_current_primary;
} term_context;
enum {
NOT_READY,
VBE,
TEXTMODE,
FALLBACK
};
extern int current_video_mode;
extern int term_backend;
extern size_t term_rows, term_cols;
extern bool term_runtime;
extern bool early_term;
extern bool term_enabled_once;
void term_fallback(void);
void term_reinit(void);
void term_deinit(void);
void term_vbe(char *config, size_t width, size_t height);
void term_textmode(void);
2021-11-20 23:47:51 +03:00
void term_notready(void);
void term_putchar(uint8_t c);
void term_write(uint64_t buf, uint64_t count);
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);
extern bool (*disable_cursor)(void);
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);
extern bool (*scroll_disable)(void);
extern void (*scroll_enable)(void);
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);
extern void (*term_revscroll)(void);
extern void (*term_swap_palette)(void);
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);
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
#define TERM_CB_DEC 10
#define TERM_CB_BELL 20
#define TERM_CB_PRIVATE_ID 30
#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
#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
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();
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
}
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