Fast and reasonably complete (framebuffer) terminal emulator (Zig fork)

Update

mintsuki 25dc8a17 dd016334

Changed files
+34 -14
backends
+18
backends/framebuffer.c
···
void *memset(void *, int, size_t);
void *memcpy(void *, const void *, size_t);
static void fbterm_swap_palette(struct term_context *_ctx) {
struct fbterm_context *ctx = (void *)_ctx;
uint32_t tmp = ctx->text_bg;
···
_ctx->scroll = fbterm_scroll;
_ctx->revscroll = fbterm_revscroll;
_ctx->swap_palette = fbterm_swap_palette;
_ctx->double_buffer_flush = fbterm_double_buffer_flush;
_ctx->full_refresh = fbterm_full_refresh;
_ctx->deinit = fbterm_deinit;
···
void *memset(void *, int, size_t);
void *memcpy(void *, const void *, size_t);
+
static void fbterm_save_state(struct term_context *_ctx) {
+
struct fbterm_context *ctx = (void *)_ctx;
+
ctx->saved_state_text_fg = ctx->text_fg;
+
ctx->saved_state_text_bg = ctx->text_bg;
+
ctx->saved_state_cursor_x = ctx->cursor_x;
+
ctx->saved_state_cursor_y = ctx->cursor_y;
+
}
+
+
static void fbterm_restore_state(struct term_context *_ctx) {
+
struct fbterm_context *ctx = (void *)_ctx;
+
ctx->text_fg = ctx->saved_state_text_fg;
+
ctx->text_bg = ctx->saved_state_text_bg;
+
ctx->cursor_x = ctx->saved_state_cursor_x;
+
ctx->cursor_y = ctx->saved_state_cursor_y;
+
}
+
static void fbterm_swap_palette(struct term_context *_ctx) {
struct fbterm_context *ctx = (void *)_ctx;
uint32_t tmp = ctx->text_bg;
···
_ctx->scroll = fbterm_scroll;
_ctx->revscroll = fbterm_revscroll;
_ctx->swap_palette = fbterm_swap_palette;
+
_ctx->save_state = fbterm_save_state;
+
_ctx->restore_state = fbterm_restore_state;
_ctx->double_buffer_flush = fbterm_double_buffer_flush;
_ctx->full_refresh = fbterm_full_refresh;
_ctx->deinit = fbterm_deinit;
+8 -8
term.c
···
#define CHARSET_DEC_SPECIAL 1
void term_context_reinit(struct term_context *ctx) {
-
ctx->scroll_enabled = true;
ctx->tab_size = 8;
-
ctx->escape_offset = 0;
ctx->control_sequence = false;
ctx->csi = false;
ctx->escape = false;
···
ctx->bold = false;
ctx->reverse_video = false;
ctx->dec_private = false;
ctx->esc_values_i = 0;
ctx->saved_cursor_x = 0;
ctx->saved_cursor_y = 0;
ctx->current_primary = (size_t)-1;
-
ctx->insert_mode = false;
ctx->scroll_top_margin = 0;
ctx->scroll_bottom_margin = ctx->rows;
-
ctx->current_charset = 0;
-
ctx->g_select = 0;
-
ctx->charsets[0] = CHARSET_DEFAULT;
-
ctx->charsets[1] = CHARSET_DEC_SPECIAL;
-
ctx->autoflush = true;
}
static void term_putchar(struct term_context *ctx, uint8_t c);
···
#define CHARSET_DEC_SPECIAL 1
void term_context_reinit(struct term_context *ctx) {
ctx->tab_size = 8;
+
ctx->autoflush = true;
+
ctx->scroll_enabled = true;
ctx->control_sequence = false;
ctx->csi = false;
ctx->escape = false;
···
ctx->bold = false;
ctx->reverse_video = false;
ctx->dec_private = false;
+
ctx->insert_mode = false;
+
ctx->g_select = 0;
+
ctx->charsets[0] = CHARSET_DEFAULT;
+
ctx->charsets[1] = CHARSET_DEC_SPECIAL;
+
ctx->current_charset = 0;
+
ctx->escape_offset = 0;
ctx->esc_values_i = 0;
ctx->saved_cursor_x = 0;
ctx->saved_cursor_y = 0;
ctx->current_primary = (size_t)-1;
ctx->scroll_top_margin = 0;
ctx->scroll_bottom_margin = ctx->rows;
}
static void term_putchar(struct term_context *ctx, uint8_t c);
+8 -6
term.h
···
#define TERM_CB_LINUX 80
struct term_context {
-
size_t rows, cols;
size_t tab_size;
-
bool autoflush;
-
-
bool in_bootloader;
-
bool scroll_enabled;
bool control_sequence;
bool csi;
···
size_t scroll_top_margin;
size_t scroll_bottom_margin;
uint32_t esc_values[TERM_MAX_ESC_VALUES];
-
bool saved_state_bold;
bool saved_state_reverse_video;
size_t saved_state_current_charset;
size_t saved_state_current_primary;
void (*raw_putchar)(struct term_context *, uint8_t c);
void (*clear)(struct term_context *, bool move);
void (*enable_cursor)(struct term_context *);
···
void (*double_buffer_flush)(struct term_context *);
void (*full_refresh)(struct term_context *);
void (*deinit)(struct term_context *, void (*)(void *, size_t));
void (*callback)(struct term_context *, uint64_t, uint64_t, uint64_t, uint64_t);
};
···
#define TERM_CB_LINUX 80
struct term_context {
+
/* internal use */
size_t tab_size;
bool autoflush;
bool scroll_enabled;
bool control_sequence;
bool csi;
···
size_t scroll_top_margin;
size_t scroll_bottom_margin;
uint32_t esc_values[TERM_MAX_ESC_VALUES];
bool saved_state_bold;
bool saved_state_reverse_video;
size_t saved_state_current_charset;
size_t saved_state_current_primary;
+
/* to be set by backend */
+
+
size_t rows, cols;
+
bool in_bootloader;
+
void (*raw_putchar)(struct term_context *, uint8_t c);
void (*clear)(struct term_context *, bool move);
void (*enable_cursor)(struct term_context *);
···
void (*double_buffer_flush)(struct term_context *);
void (*full_refresh)(struct term_context *);
void (*deinit)(struct term_context *, void (*)(void *, size_t));
+
+
/* to be set by client */
void (*callback)(struct term_context *, uint64_t, uint64_t, uint64_t, uint64_t);
};