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

Move enable/disable cursor to frontend

mintsuki 2fcb7e6d 5d3e0ddc

Changed files
+7 -25
backends
+3 -21
backends/framebuffer.c
···
}
}
-
static void fbterm_enable_cursor(struct term_context *_ctx) {
-
struct fbterm_context *ctx = (void *)_ctx;
-
-
ctx->cursor_status = true;
-
}
-
-
static bool fbterm_disable_cursor(struct term_context *_ctx) {
-
struct fbterm_context *ctx = (void *)_ctx;
-
-
bool ret = ctx->cursor_status;
-
ctx->cursor_status = false;
-
return ret;
-
}
-
static void fbterm_set_cursor_pos(struct term_context *_ctx, size_t x, size_t y) {
struct fbterm_context *ctx = (void *)_ctx;
···
static void fbterm_double_buffer_flush(struct term_context *_ctx) {
struct fbterm_context *ctx = (void *)_ctx;
-
if (ctx->cursor_status) {
+
if (_ctx->cursor_enabled) {
draw_cursor(_ctx);
}
···
ctx->map[offset] = NULL;
}
-
if ((ctx->old_cursor_x != ctx->cursor_x || ctx->old_cursor_y != ctx->cursor_y) || ctx->cursor_status == false) {
+
if ((ctx->old_cursor_x != ctx->cursor_x || ctx->old_cursor_y != ctx->cursor_y) || _ctx->cursor_enabled == false) {
if (ctx->old_cursor_x < _ctx->cols && ctx->old_cursor_y < _ctx->rows) {
plot_char(_ctx, &ctx->grid[ctx->old_cursor_x + ctx->old_cursor_y * _ctx->cols], ctx->old_cursor_x, ctx->old_cursor_y);
}
···
plot_char(_ctx, &ctx->grid[i], x, y);
}
-
if (ctx->cursor_status) {
+
if (_ctx->cursor_enabled) {
draw_cursor(_ctx);
}
}
···
struct term_context *_ctx = (void *)ctx;
memset(ctx, 0, sizeof(struct fbterm_context));
-
-
ctx->cursor_status = true;
if (ansi_colours != NULL) {
memcpy(ctx->ansi_colours, ansi_colours, sizeof(ctx->ansi_colours));
···
_ctx->raw_putchar = fbterm_raw_putchar;
_ctx->clear = fbterm_clear;
-
_ctx->enable_cursor = fbterm_enable_cursor;
-
_ctx->disable_cursor = fbterm_disable_cursor;
_ctx->set_cursor_pos = fbterm_set_cursor_pos;
_ctx->get_cursor_pos = fbterm_get_cursor_pos;
_ctx->set_text_fg = fbterm_set_text_fg;
+3 -2
term.c
···
void term_context_reinit(struct term_context *ctx) {
ctx->tab_size = 8;
ctx->autoflush = true;
+
ctx->cursor_enabled = true;
ctx->scroll_enabled = true;
ctx->control_sequence = false;
ctx->csi = false;
···
switch (ctx->esc_values[0]) {
case 25: {
if (set) {
-
ctx->enable_cursor(ctx);
+
ctx->cursor_enabled = true;
} else {
-
ctx->disable_cursor(ctx);
+
ctx->cursor_enabled = false;
}
return;
}
+1 -2
term.h
···
size_t tab_size;
bool autoflush;
+
bool cursor_enabled;
bool scroll_enabled;
bool control_sequence;
bool csi;
···
void (*raw_putchar)(struct term_context *, uint8_t c);
void (*clear)(struct term_context *, bool move);
-
void (*enable_cursor)(struct term_context *);
-
bool (*disable_cursor)(struct term_context *);
void (*set_cursor_pos)(struct term_context *, size_t x, size_t y);
void (*get_cursor_pos)(struct term_context *, size_t *x, size_t *y);
void (*set_text_fg)(struct term_context *, size_t fg);