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 scroll_enabled;
29 bool control_sequence;
30 bool csi;
31 bool escape;
32 bool osc;
33 bool osc_escape;
34 bool rrr;
35 bool discard_next;
36 bool bold;
37 bool bg_bold;
38 bool reverse_video;
39 bool dec_private;
40 bool insert_mode;
41 uint8_t g_select;
42 uint8_t charsets[2];
43 size_t current_charset;
44 size_t escape_offset;
45 size_t esc_values_i;
46 size_t saved_cursor_x;
47 size_t saved_cursor_y;
48 size_t current_primary;
49 size_t current_bg;
50 size_t scroll_top_margin;
51 size_t scroll_bottom_margin;
52 uint32_t esc_values[TERM_MAX_ESC_VALUES];
53 bool saved_state_bold;
54 bool saved_state_bg_bold;
55 bool saved_state_reverse_video;
56 size_t saved_state_current_charset;
57 size_t saved_state_current_primary;
58 size_t saved_state_current_bg;
59
60 /* to be set by backend */
61
62 size_t rows, cols;
63 bool in_bootloader;
64
65 void (*raw_putchar)(struct term_context *, uint8_t c);
66 void (*clear)(struct term_context *, bool move);
67 void (*enable_cursor)(struct term_context *);
68 bool (*disable_cursor)(struct term_context *);
69 void (*set_cursor_pos)(struct term_context *, size_t x, size_t y);
70 void (*get_cursor_pos)(struct term_context *, size_t *x, size_t *y);
71 void (*set_text_fg)(struct term_context *, size_t fg);
72 void (*set_text_bg)(struct term_context *, size_t bg);
73 void (*set_text_fg_bright)(struct term_context *, size_t fg);
74 void (*set_text_bg_bright)(struct term_context *, size_t bg);
75 void (*set_text_fg_rgb)(struct term_context *, uint32_t fg);
76 void (*set_text_bg_rgb)(struct term_context *, uint32_t bg);
77 void (*set_text_fg_default)(struct term_context *);
78 void (*set_text_bg_default)(struct term_context *);
79 void (*move_character)(struct term_context *, size_t new_x, size_t new_y, size_t old_x, size_t old_y);
80 void (*scroll)(struct term_context *);
81 void (*revscroll)(struct term_context *);
82 void (*swap_palette)(struct term_context *);
83 void (*save_state)(struct term_context *);
84 void (*restore_state)(struct term_context *);
85 void (*double_buffer_flush)(struct term_context *);
86 void (*full_refresh)(struct term_context *);
87 void (*deinit)(struct term_context *, void (*)(void *, size_t));
88
89 /* to be set by client */
90
91 void (*callback)(struct term_context *, uint64_t, uint64_t, uint64_t, uint64_t);
92};
93
94void term_context_reinit(struct term_context *ctx);
95void term_write(struct term_context *ctx, const char *buf, size_t count);
96
97#ifdef __cplusplus
98}
99#endif
100
101#endif