From 2363b859e13783b48dd6723c0d90934cb5849cf6 Mon Sep 17 00:00:00 2001 From: xolatile Date: Wed, 20 Sep 2023 07:46:24 -0400 Subject: [PATCH] Cleaned few bugs and added carrige return plus line feed... --- xurses.c | 22 +++++++++++++++------- xurses.h | 1 + 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/xurses.c b/xurses.c index f620b6d..3a2baea 100644 --- a/xurses.c +++ b/xurses.c @@ -27,10 +27,10 @@ struct termios curses_old_terminal; struct termios curses_new_terminal; void curses_initialize (void) { - char key; - struct winsize screen_dimension; + char i = 0; + fatal_failure (ioctl (STDOUT_FILENO, TIOCGWINSZ, & screen_dimension) == -1, "ioctl: Failed to get terminal dimensions."); curses_screen_width = (int) screen_dimension.ws_col; @@ -50,13 +50,19 @@ void curses_initialize (void) { fatal_failure (tcsetattr (STDIN_FILENO, TCSAFLUSH, & curses_new_terminal) == -1, "tcsetattr: Failed to set reverse terminal attributes."); - curses_screen = allocate (CURSES_OFFSET + CURSES_LENGTH * curses_screen_width * curses_screen_height + 1); + curses_screen = allocate (CURSES_OFFSET + CURSES_LENGTH * curses_screen_width * curses_screen_height + (curses_screen_height - 1) * CURSES_RETURN + 1); - for (key = ' '; key != '~'; ++key) { - curses_unbind (key); + for (i = ' '; i != '~'; ++i) { + curses_unbind ((char) i); } terminal_clear (); + + curses_screen_offset (); + + for (i = 0; i != curses_screen_height - 1; ++i) { + string_copy_limit (& curses_screen [CURSES_LENGTH * curses_screen_width * i + CURSES_OFFSET], "\r\n", string_length ("\r\n")); + } } void curses_deinitialize (void) { @@ -69,8 +75,10 @@ void curses_deinitialize (void) { void curses_synchronize (void) { curses_signal = '\0'; - +/* out (curses_screen, curses_screen_size); +*/ + out (curses_screen, CURSES_OFFSET + CURSES_LENGTH * curses_screen_width * curses_screen_height); in (& curses_signal, 1); @@ -92,7 +100,7 @@ char * curses_screen_position (int x, int y) { fatal_failure (x >= curses_screen_width, "curses_screen_position: X position is beyond the upper bound."); fatal_failure (y >= curses_screen_height, "curses_screen_position: Y position is beyond the upper bound."); - return (& curses_screen [CURSES_LENGTH * (y * curses_screen_width + x) + CURSES_OFFSET]); + return (& curses_screen [CURSES_LENGTH * (y * curses_screen_width + x) + y * CURSES_RETURN + CURSES_OFFSET]); } char * curses_format_character (char character, int colour, int effect) { diff --git a/xurses.h b/xurses.h index 098e76d..0b253d3 100644 --- a/xurses.h +++ b/xurses.h @@ -19,6 +19,7 @@ #define CURSES_LENGTH ((int) sizeof ("\033[-;3-m-\033[0m") - 1) #define CURSES_OFFSET ((int) sizeof ("\033[H") - 1) +#define CURSES_RETURN ((int) sizeof ("\r\n") - 1) extern int curses_active; extern int curses_cursor;