From 3bef00913abfd8ec24eaba3778be1386136b59b3 Mon Sep 17 00:00:00 2001 From: Mitchell Waite Date: Thu, 12 Feb 2026 18:04:23 -0500 Subject: [PATCH 1/2] add function to get x/y position of the console cursor, clear to eol starting from a given position --- libxenon/drivers/console/console.c | 25 +++++++++++++++++++++---- libxenon/drivers/console/console.h | 5 +++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/libxenon/drivers/console/console.c b/libxenon/drivers/console/console.c index faab3870..4a14b1ea 100644 --- a/libxenon/drivers/console/console.c +++ b/libxenon/drivers/console/console.c @@ -98,10 +98,17 @@ void console_clrscr() { } void console_clrline() { - char sp[max_x]; - memset(sp,' ', max_x); - sp[max_x-1]='\0'; - printf("\r%s\r",sp); + console_clear_to_eol(0); +} + +void console_clear_to_eol(int startpos) { + char sp[max_x - startpos]; + memset(sp,' ', max_x - startpos); + sp[max_x - startpos - 1]='\0'; + + cursor_x = startpos; + printf("%s",sp); + cursor_x = startpos; } static void console_scroll32(const unsigned int lines) { @@ -206,6 +213,16 @@ void console_get_dimensions(unsigned int * width,unsigned int * height){ if (height) *height=max_y; } +int console_get_cursor_x(void) +{ + return cursor_x; +} + +int console_get_cursor_y(void) +{ + return cursor_y; +} + void console_open(void) { stdout_hook = console_stdout_hook; diff --git a/libxenon/drivers/console/console.h b/libxenon/drivers/console/console.h index d1394986..b6e4ca32 100644 --- a/libxenon/drivers/console/console.h +++ b/libxenon/drivers/console/console.h @@ -41,12 +41,17 @@ void console_get_dimensions(unsigned int * width,unsigned int * height); void console_putch(const char c); void console_clrscr(); void console_clrline(); +void console_clear_to_eol(int start_pos); + void console_init(void); void console_open(void); void console_close(void); void console_pset(int x, int y, unsigned char r, unsigned char g, unsigned char b); void console_pset_right(int x, int y, unsigned char r, unsigned char g, unsigned char b); +int console_get_cursor_x(void); +int console_get_cursor_y(void); + #ifdef __cplusplus }; #endif From 41a973e6b848ceb0802f6da40a1cf6489edc3950 Mon Sep 17 00:00:00 2001 From: Mitchell Waite Date: Thu, 12 Feb 2026 18:09:30 -0500 Subject: [PATCH 2/2] Add some more functions that might be useful --- libxenon/drivers/console/console.c | 17 +++++++++++++++++ libxenon/drivers/console/console.h | 3 +++ 2 files changed, 20 insertions(+) diff --git a/libxenon/drivers/console/console.c b/libxenon/drivers/console/console.c index 4a14b1ea..704c8640 100644 --- a/libxenon/drivers/console/console.c +++ b/libxenon/drivers/console/console.c @@ -223,6 +223,23 @@ int console_get_cursor_y(void) return cursor_y; } +int console_get_cursor_max_x(void) +{ + return max_x; +} + +int console_get_cursor_max_y(void) +{ + return max_y; +} + + +void console_set_cursor(int x, int y) +{ + cursor_x = x; + cursor_y = y; +} + void console_open(void) { stdout_hook = console_stdout_hook; diff --git a/libxenon/drivers/console/console.h b/libxenon/drivers/console/console.h index b6e4ca32..f6b33539 100644 --- a/libxenon/drivers/console/console.h +++ b/libxenon/drivers/console/console.h @@ -51,6 +51,9 @@ void console_pset_right(int x, int y, unsigned char r, unsigned char g, unsigned int console_get_cursor_x(void); int console_get_cursor_y(void); +int console_get_cursor_max_x(void); +int console_get_cursor_max_y(void); +void console_set_cursor(int x, int y); #ifdef __cplusplus };