Fast and reasonably complete (framebuffer) terminal emulator (Zig fork)
1#ifndef _TERM_H 2#define _TERM_H 3 4#ifdef __cplusplus 5extern "C" { 6#endif 7 8#include <stddef.h> 9#include <stdint.h> 10#include <stdbool.h> 11 12#define TERM_MAX_ESC_VALUES 16 13 14#define TERM_CB_DEC 10 15#define TERM_CB_BELL 20 16#define TERM_CB_PRIVATE_ID 30 17#define TERM_CB_STATUS_REPORT 40 18#define TERM_CB_POS_REPORT 50 19#define TERM_CB_KBD_LEDS 60 20#define TERM_CB_MODE 70 21#define TERM_CB_LINUX 80 22 23struct term_context { 24 /* internal use */ 25 26 size_t tab_size; 27 bool autoflush; 28 bool cursor_enabled; 29 bool scroll_enabled; 30 bool control_sequence; 31 bool csi; 32 bool escape; 33 bool osc; 34 bool osc_escape; 35 bool rrr; 36 bool discard_next; 37 bool bold; 38 bool bg_bold; 39 bool reverse_video; 40 bool dec_private; 41 bool insert_mode; 42 uint64_t code_point; 43 size_t unicode_remaining; 44 uint8_t g_select; 45 uint8_t charsets[2]; 46 size_t current_charset; 47 size_t escape_offset; 48 size_t esc_values_i; 49 size_t saved_cursor_x; 50 size_t saved_cursor_y; 51 size_t current_primary; 52 size_t current_bg; 53 size_t scroll_top_margin; 54 size_t scroll_bottom_margin; 55 uint32_t esc_values[TERM_MAX_ESC_VALUES]; 56 bool saved_state_bold; 57 bool saved_state_bg_bold; 58 bool saved_state_reverse_video; 59 size_t saved_state_current_charset; 60 size_t saved_state_current_primary; 61 size_t saved_state_current_bg; 62 63 /* to be set by backend */ 64 65 size_t rows, cols; 66 bool in_bootloader; 67 68 void (*raw_putchar)(struct term_context *, uint8_t c); 69 void (*clear)(struct term_context *, bool move); 70 void (*set_cursor_pos)(struct term_context *, size_t x, size_t y); 71 void (*get_cursor_pos)(struct term_context *, size_t *x, size_t *y); 72 void (*set_text_fg)(struct term_context *, size_t fg); 73 void (*set_text_bg)(struct term_context *, size_t bg); 74 void (*set_text_fg_bright)(struct term_context *, size_t fg); 75 void (*set_text_bg_bright)(struct term_context *, size_t bg); 76 void (*set_text_fg_rgb)(struct term_context *, uint32_t fg); 77 void (*set_text_bg_rgb)(struct term_context *, uint32_t bg); 78 void (*set_text_fg_default)(struct term_context *); 79 void (*set_text_bg_default)(struct term_context *); 80 void (*set_text_fg_default_bright)(struct term_context *); 81 void (*set_text_bg_default_bright)(struct term_context *); 82 void (*move_character)(struct term_context *, size_t new_x, size_t new_y, size_t old_x, size_t old_y); 83 void (*scroll)(struct term_context *); 84 void (*revscroll)(struct term_context *); 85 void (*swap_palette)(struct term_context *); 86 void (*save_state)(struct term_context *); 87 void (*restore_state)(struct term_context *); 88 void (*double_buffer_flush)(struct term_context *); 89 void (*full_refresh)(struct term_context *); 90 void (*deinit)(struct term_context *, void (*)(void *, size_t)); 91 92 /* to be set by client */ 93 94 void (*callback)(struct term_context *, uint64_t, uint64_t, uint64_t, uint64_t); 95}; 96 97void term_context_reinit(struct term_context *ctx); 98void term_write(struct term_context *ctx, const char *buf, size_t count); 99 100#ifdef __cplusplus 101} 102#endif 103 104#endif