Updated long ago...

This commit is contained in:
Ognjen Milan Robovic 2023-09-18 16:17:08 -04:00
parent 8b48742902
commit c129af921a
3 changed files with 75 additions and 25 deletions

View File

@ -2,7 +2,7 @@
set -xe
sudo cp xurses.h /usr/include/xolatile/xurses.h
sudo cp xurses.c /usr/include/xolatile/xurses.c
cp xurses.h /usr/include/xolatile/xurses.h
cp xurses.c /usr/include/xolatile/xurses.c
exit

View File

@ -13,7 +13,7 @@
int curses_active = 1;
int curses_cursor = 0;
char curses_signal = 0;
char curses_signal = '\0';
int curses_screen_width = 0;
int curses_screen_height = 0;
int curses_screen_size = 0;
@ -48,19 +48,15 @@ void curses_initialize (void) {
fatal_failure (tcsetattr (STDIN_FILENO, TCSAFLUSH, & curses_new_terminal) == -1, "[!] tcsetattr: Failed to set raw terminal attributes.");
curses_screen = allocate (12 * curses_screen_width * curses_screen_height + 8);
string_copy_limit (& curses_screen [0], "\033[2J\033[H", 7);
curses_screen = allocate (12 * (curses_screen_width + 2) * curses_screen_height + 8);
for (key = ' '; key != '~'; ++key) {
curses_unbind (key);
}
//~write (STDOUT_FILENO, "\033[25h", sizeof ("\033[25h"));
}
void curses_deinitialize (void) {
free (curses_screen);
curses_screen = deallocate (curses_screen);
out ("\033[2J\033[H", 7);
@ -68,27 +64,82 @@ void curses_deinitialize (void) {
}
void curses_synchronize (void) {
curses_signal = 0;
curses_signal = '\0';
out (curses_screen, 12 * curses_screen_width * curses_screen_height + 8);
out (curses_screen, curses_screen_size);
in (& curses_signal, 1);
if ((curses_signal < ' ') || (curses_signal > '~')) {
return;
} else {
curses_screen_size = 0;
if ((curses_signal >= ' ') && (curses_signal <= '~')) {
curses_action [curses_signal - ' '] ();
}
string_copy_limit (& curses_screen [curses_screen_size], "\033[H", 3);
curses_screen_size += 3;
}
void curses_blank (void) {
int i, j;
for (i = 0; i != curses_screen_height; ++i) {
for (j = 0; j != curses_screen_width; ++j) {
curses_character (' ', EFFECT_NORMAL, COLOUR_WHITE, j, i);
}
}
}
void curses_character (char character, int effect, int colour, int x, int y) {
char format [12] = "\033[ ;3 m \033[0m";
char format [13] = "\033[ ;3 m \033[0m";
format [2] = (char) effect + '0';
format [5] = (char) colour + '0';
format [7] = character;
string_copy_limit (& curses_screen [(y * curses_screen_width + x) * 12 + 7], format, 12);
string_copy_limit (& curses_screen [(y * (curses_screen_width + 2) + x) * 12 + 3], format, 12);
curses_screen_size += 12;
}
void curses_append_character (char character, int effect, int colour) {
char format [13] = "\033[ ;3 m \033[0m";
format [2] = (char) effect + '0';
format [5] = (char) colour + '0';
format [7] = character;
string_copy_limit (& curses_screen [curses_screen_size], format, 12);
curses_screen_size += 12;
}
void curses_append_string (char * string, int effect, int colour, int length) {
char format [8] = "\033[ ;3 m";
format [2] = (char) effect + '0';
format [5] = (char) colour + '0';
string_copy_limit (& curses_screen [curses_screen_size], format, 7);
curses_screen_size += 7;
string_copy_limit (& curses_screen [curses_screen_size], string, length);
curses_screen_size += length;
string_copy_limit (& curses_screen [curses_screen_size], "\033[0m", 4);
curses_screen_size += 4;
}
void curses_append_cursor (int cursor_x, int cursor_y) {
char format [11] = "\033[000;000H";
format [4] = (char) (cursor_y / 1) % 10 + '0';
format [3] = (char) (cursor_y / 10) % 10 + '0';
format [2] = (char) (cursor_y / 100) % 10 + '0';
format [8] = (char) (cursor_x / 1) % 10 + '0';
format [7] = (char) (cursor_x / 10) % 10 + '0';
format [6] = (char) (cursor_x / 100) % 10 + '0';
string_copy_limit (& curses_screen [curses_screen_size], format, 10);
curses_screen_size += 10;
}
void curses_style (int effect, int colour) {
@ -116,10 +167,6 @@ void curses_show_cursor (int show) {
}
}
void curses_move_cursor (int x, int y) {
out ("\033[H", 4); /* yx */
}
void curses_bind (char key, void (* action) (void)) {
curses_action [key - ' '] = action;
}

View File

@ -35,11 +35,14 @@ extern void curses_initialize (void);
extern void curses_deinitialize (void);
extern void curses_synchronize (void);
extern void curses_character (char, int, int, int, int);
extern void curses_style (int, int);
extern void curses_clear (void);
extern void curses_show_cursor (int);
extern void curses_move_cursor (int, int);
extern void curses_blank (void);
extern void curses_character (char, int, int, int, int);
extern void curses_append_character (char, int, int);
extern void curses_append_string (char *, int, int, int);
extern void curses_append_cursor (int, int);
extern void curses_style (int, int);
extern void curses_clear (void);
extern void curses_show_cursor (int);
extern void curses_bind (char, void (*) (void));
extern void curses_unbind (char);