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

Fix bug introduced in 9225cfb1 that resulted in hangs

mintsuki a82ef0a1 6ee3fe00

Changed files
+11 -9
backends
+11 -9
backends/framebuffer.c
···
static void fbterm_get_cursor_pos(struct term_context *_ctx, size_t *x, size_t *y) {
struct fbterm_context *ctx = (void *)_ctx;
-
*x = ctx->cursor_x;
-
*y = ctx->cursor_y;
+
*x = ctx->cursor_x >= _ctx->cols ? _ctx->cols - 1 : ctx->cursor_x;
+
*y = ctx->cursor_y >= _ctx->rows ? _ctx->rows - 1 : ctx->cursor_y;
}
static void fbterm_move_character(struct term_context *_ctx, size_t new_x, size_t new_y, size_t old_x, size_t old_y) {
···
static void draw_cursor(struct term_context *_ctx) {
struct fbterm_context *ctx = (void *)_ctx;
-
size_t i = ctx->cursor_x + ctx->cursor_y * _ctx->cols;
-
-
if (i >= _ctx->cols * _ctx->rows) {
+
if (ctx->cursor_x >= _ctx->cols || ctx->cursor_y >= _ctx->rows) {
return;
}
+
+
size_t i = ctx->cursor_x + ctx->cursor_y * _ctx->cols;
struct fbterm_char c;
struct fbterm_queue_item *q = ctx->map[i];
···
}
if ((ctx->old_cursor_x != ctx->cursor_x || ctx->old_cursor_y != ctx->cursor_y) || ctx->cursor_status == false) {
-
plot_char(_ctx, &ctx->grid[ctx->old_cursor_x + ctx->old_cursor_y * _ctx->cols], ctx->old_cursor_x, ctx->old_cursor_y);
+
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);
+
}
}
ctx->old_cursor_x = ctx->cursor_x;
···
static void fbterm_raw_putchar(struct term_context *_ctx, uint8_t c) {
struct fbterm_context *ctx = (void *)_ctx;
-
if (ctx->cursor_x == _ctx->cols && (ctx->cursor_y < _ctx->scroll_bottom_margin - 1 || _ctx->scroll_enabled)) {
+
if (ctx->cursor_x >= _ctx->cols && (ctx->cursor_y < _ctx->scroll_bottom_margin - 1 || _ctx->scroll_enabled)) {
ctx->cursor_x = 0;
ctx->cursor_y++;
}
-
if (ctx->cursor_y == _ctx->scroll_bottom_margin) {
-
ctx->cursor_y--;
+
if (ctx->cursor_y >= _ctx->scroll_bottom_margin) {
+
ctx->cursor_y = _ctx->scroll_bottom_margin - 1;
fbterm_scroll(_ctx);
}