I need to revise this...

This commit is contained in:
Ognjen Milan Robovic 2023-10-04 17:49:10 -04:00
parent d60f1c0574
commit ce3cf55e02
3 changed files with 37 additions and 21 deletions

View File

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

View File

@ -21,7 +21,7 @@ char * curses_screen = NULL;
char curses_format [CURSES_LENGTH + 1] = "\033[-;3-m-\033[0m";
void (* curses_action ['~' - ' ' + 1]) (void) = { 0 };
void (* curses_action [SIGNAL_COUNT]) (void) = { 0 };
struct termios curses_old_terminal;
struct termios curses_new_terminal;
@ -29,7 +29,8 @@ struct termios curses_new_terminal;
void curses_initialize (void) {
struct winsize screen_dimension;
char i = 0;
char signal = 0;
char offset = 0;
fatal_failure (ioctl (STDOUT_FILENO, TIOCGWINSZ, & screen_dimension) == -1, "ioctl: Failed to get terminal dimensions.");
@ -52,16 +53,16 @@ void curses_initialize (void) {
curses_screen = allocate (CURSES_OFFSET + CURSES_LENGTH * curses_screen_width * curses_screen_height + (curses_screen_height - 1) * CURSES_RETURN + 1);
for (i = ' '; i != '~'; ++i) {
curses_unbind ((char) i);
for (signal = SIGNAL_NONE; signal != SIGNAL_COUNT; ++signal) {
curses_unbind ((char) signal);
}
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"));
for (offset = 0; offset != curses_screen_height - 1; ++offset) {
string_copy (& curses_screen [CURSES_LENGTH * curses_screen_width * offset + CURSES_OFFSET], "\r\n");
}
}
@ -78,19 +79,32 @@ void curses_synchronize (void) {
/*
out (curses_screen, curses_screen_size);
*/
out (curses_screen, CURSES_OFFSET + CURSES_LENGTH * curses_screen_width * curses_screen_height);
out (curses_screen, CURSES_OFFSET + CURSES_LENGTH * curses_screen_width * curses_screen_height/* + curses_screen_height * CURSES_RETURN*/);
in (& curses_signal, 1);
if ((curses_signal >= ' ') && (curses_signal <= '~')) {
curses_action [curses_signal - ' '] ();
switch (curses_signal) {
case '0': curses_signal = SIGNAL_0; break;
case 'Q': curses_signal = SIGNAL_Q | SIGNAL_SHIFT; break;
case 'q': curses_signal = SIGNAL_Q; break;
default: curses_signal = SIGNAL_NONE; break;
}
if ((curses_signal > SIGNAL_ANY) && (curses_signal < SIGNAL_COUNT)) {
curses_action [curses_signal] ();
}
curses_screen_offset ();
}
void curses_configure (void) {
atexit (curses_deinitialize);
curses_initialize ();
}
void curses_screen_offset (void) {
string_copy_limit (& curses_screen [0], "\033[H", CURSES_OFFSET);
string_copy (& curses_screen [0], "\033[H");
curses_screen_size = CURSES_OFFSET;
}
@ -173,12 +187,12 @@ void curses_blank (void) {
}
}
void curses_bind (char key, void (* action) (void)) {
curses_action [key - ' '] = action;
void curses_bind (int signal, void (* action) (void)) {
curses_action [signal] = action;
}
void curses_unbind (char key) {
curses_action [key - ' '] = curses_idle;
void curses_unbind (int signal) {
curses_action [signal] = curses_idle;
}
void curses_idle (void) {

View File

@ -30,14 +30,16 @@ extern char * curses_screen;
extern char curses_format [CURSES_LENGTH + 1];
extern void (* curses_action ['~' - ' ' + 1]) (void);
extern void (* curses_action [SIGNAL_COUNT]) (void);
extern struct termios curses_old_terminal;
extern struct termios curses_new_terminal;
extern void curses_initialize (void);
extern void curses_deinitialize (void);
extern void curses_synchronize (void);
extern void curses_initialize (void);
extern void curses_deinitialize (void);
extern void curses_synchronize (void);
extern void curses_configure (void);
extern void curses_screen_offset (void);
extern char * curses_screen_position (int, int);
@ -49,8 +51,8 @@ extern void curses_render_character (char, int, int, int, int);
extern void curses_append_cursor (int, int);*/
extern void curses_blank (void);
extern void curses_bind (char, void (*) (void));
extern void curses_unbind (char);
extern void curses_bind (int, void (*) (void));
extern void curses_unbind (int);
extern void curses_idle (void);
extern void curses_exit (void);