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