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