:: commit 2ee939725ed80a68684159afda4aba616fb9d26a

mintsuki <mintsuki@protonmail.com> — 2022-12-30 06:58

parents: 1aba6b3aeb

term: Compatibility with new terminal code

diff --git a/common/drivers/vga_textmode.c b/common/drivers/vga_textmode.c
index 014c0f95..2acbf4ca 100644
--- a/common/drivers/vga_textmode.c
+++ b/common/drivers/vga_textmode.c
@@ -81,20 +81,6 @@ static void text_clear(struct term_context *_ctx, bool move) {
     }
 }
 
-static void text_enable_cursor(struct term_context *_ctx) {
-    struct textmode_context *ctx = (void *)_ctx;
-
-    ctx->cursor_status = true;
-}
-
-static bool text_disable_cursor(struct term_context *_ctx) {
-    struct textmode_context *ctx = (void *)_ctx;
-
-    bool ret = ctx->cursor_status;
-    ctx->cursor_status = false;
-    return ret;
-}
-
 static void text_full_refresh(struct term_context *_ctx) {
     struct textmode_context *ctx = (void *)_ctx;
 
@@ -103,7 +89,7 @@ static void text_full_refresh(struct term_context *_ctx) {
         ctx->back_buffer[i] = ctx->front_buffer[i];
     }
 
-    if (ctx->cursor_status) {
+    if (_ctx->cursor_enabled) {
         draw_cursor(ctx);
         ctx->old_cursor_offset = ctx->cursor_offset;
     }
@@ -112,11 +98,11 @@ static void text_full_refresh(struct term_context *_ctx) {
 static void text_double_buffer_flush(struct term_context *_ctx) {
     struct textmode_context *ctx = (void *)_ctx;
 
-    if (ctx->cursor_status) {
+    if (_ctx->cursor_enabled) {
         draw_cursor(ctx);
     }
 
-    if (ctx->cursor_offset != ctx->old_cursor_offset || ctx->cursor_status == false) {
+    if (ctx->cursor_offset != ctx->old_cursor_offset || _ctx->cursor_enabled == false) {
         ctx->video_mem[ctx->old_cursor_offset + 1] = ctx->back_buffer[ctx->old_cursor_offset + 1];
     }
 
@@ -125,7 +111,7 @@ static void text_double_buffer_flush(struct term_context *_ctx) {
             continue;
         }
 
-        if (ctx->cursor_status && i == ctx->cursor_offset + 1) {
+        if (_ctx->cursor_enabled && i == ctx->cursor_offset + 1) {
             continue;
         }
 
@@ -133,7 +119,7 @@ static void text_double_buffer_flush(struct term_context *_ctx) {
         ctx->video_mem[i]    = ctx->back_buffer[i];
     }
 
-    if (ctx->cursor_status) {
+    if (_ctx->cursor_enabled) {
         ctx->old_cursor_offset = ctx->cursor_offset;
     }
 }
@@ -299,7 +285,6 @@ void vga_textmode_init(bool managed) {
     }
 
     ctx->cursor_offset = 0;
-    ctx->cursor_status = true;
     ctx->text_palette = 0x07;
 
     ctx->video_mem = (volatile uint8_t *)0xb8000;
@@ -309,7 +294,7 @@ void vga_textmode_init(bool managed) {
     // VGA cursor code taken from: https://wiki.osdev.org/Text_Mode_Cursor
 
     if (!managed) {
-        text_disable_cursor(term);
+        term->cursor_enabled = false;
 
         outb(0x3d4, 0x0a);
         outb(0x3d5, (inb(0x3d5) & 0xc0) | 14);
@@ -340,8 +325,6 @@ void vga_textmode_init(bool managed) {
 
     term->raw_putchar = text_putchar;
     term->clear = text_clear;
-    term->enable_cursor = text_enable_cursor;
-    term->disable_cursor = text_disable_cursor;
     term->set_cursor_pos = text_set_cursor_pos;
     term->get_cursor_pos = text_get_cursor_pos;
     term->set_text_fg = text_set_text_fg;
diff --git a/common/lib/readline.c b/common/lib/readline.c
index 8fb97eb7..1a03d9dc 100644
--- a/common/lib/readline.c
+++ b/common/lib/readline.c
@@ -352,12 +352,12 @@ again:
 
 static void reprint_string(int x, int y, const char *s) {
     size_t orig_x, orig_y;
-    FOR_TERM(TERM->disable_cursor(TERM));
+    FOR_TERM(TERM->cursor_enabled = false);
     terms[0]->get_cursor_pos(terms[0], &orig_x, &orig_y);
     set_cursor_pos_helper(x, y);
     print("%s", s);
     set_cursor_pos_helper(orig_x, orig_y);
-    FOR_TERM(TERM->enable_cursor(TERM));
+    FOR_TERM(TERM->cursor_enabled = true);
 }
 
 static void cursor_back(void) {
diff --git a/common/lib/term.c b/common/lib/term.c
index d6421585..0034cebc 100644
--- a/common/lib/term.c
+++ b/common/lib/term.c
@@ -178,8 +178,6 @@ void term_fallback(void) {
 
         fallback_clear(NULL, true);
 
-        term->enable_cursor = (void *)dummy_handle;
-        term->disable_cursor = (void *)dummy_handle;
         term->set_text_fg = (void *)dummy_handle;
         term->set_text_bg = (void *)dummy_handle;
         term->set_text_fg_bright = (void *)dummy_handle;
diff --git a/common/lib/term.h b/common/lib/term.h
index abc05856..47812fb7 100644
--- a/common/lib/term.h
+++ b/common/lib/term.h
@@ -42,7 +42,7 @@ inline void reset_term(void) {
         print("\e[2J\e[H");
         term_context_reinit(term);
         term->in_bootloader = true;
-        term->enable_cursor(term);
+        term->cursor_enabled = true;
         term->double_buffer_flush(term);
     }
 }
diff --git a/common/menu.c b/common/menu.c
index a2f764aa..fe7a6a64 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -170,7 +170,7 @@ static bool editor_no_term_reset = false;
 char *config_entry_editor(const char *title, const char *orig_entry) {
     FOR_TERM(TERM->autoflush = false);
 
-    FOR_TERM(TERM->enable_cursor(TERM));
+    FOR_TERM(TERM->cursor_enabled = true);
 
     print("\e[2J\e[H");
 
@@ -214,7 +214,7 @@ refresh:
     invalid_syntax = false;
 
     print("\e[2J\e[H");
-    FOR_TERM(TERM->disable_cursor(TERM));
+    FOR_TERM(TERM->cursor_enabled = false);
     {
         size_t x, y;
         print("\n");
@@ -423,7 +423,7 @@ refresh:
 
     // Hack to redraw the cursor
     set_cursor_pos_helper(cursor_x, cursor_y);
-    FOR_TERM(TERM->enable_cursor(TERM));
+    FOR_TERM(TERM->cursor_enabled = true);
 
     FOR_TERM(TERM->double_buffer_flush(TERM));
 
@@ -730,7 +730,7 @@ refresh:
 
     FOR_TERM(TERM->autoflush = false);
 
-    FOR_TERM(TERM->disable_cursor(TERM));
+    FOR_TERM(TERM->cursor_enabled = false);
 
     print("\e[2J\e[H");
     {
@@ -747,7 +747,7 @@ refresh:
             quiet = false;
             menu_init_term();
             FOR_TERM(TERM->autoflush = false);
-            FOR_TERM(TERM->disable_cursor(TERM));
+            FOR_TERM(TERM->cursor_enabled = false);
         }
         print("Config file %s.\n\n", config_ready ? "contains no valid entries" : "not found");
         print("For information on the format of Limine config entries, consult CONFIG.md in\n");
tab: 248 wrap: offon