Added string rendering...
This commit is contained in:
parent
a845ae9b50
commit
a9dfe20c6a
68
xurses.c
68
xurses.c
@ -18,8 +18,9 @@ It is distributed in the hope that it will be useful or harmful, it really depen
|
||||
|
||||
/* Internal constant definitions. */
|
||||
|
||||
#define CURSES_OFFSET ((int) sizeof ("\033[-;3-m-\033[0m") - 1)
|
||||
#define CURSES_FORMAT ((int) sizeof ("\033[-;3-m-\033[0m") - 1)
|
||||
#define CURSES_REVERT ((int) sizeof ("\033[H") - 1)
|
||||
#define CURSES_CURSOR ((int) sizeof ("\033[---;---H") - 1)
|
||||
|
||||
/* Internal variable definitions. */
|
||||
|
||||
@ -28,6 +29,8 @@ static int curses_screen_width = 0;
|
||||
static int curses_screen_height = 0;
|
||||
static char * curses_screen = NULL;
|
||||
|
||||
static char curses_format [CURSES_FORMAT + 1] = "\033[-;3-m-\033[0m";
|
||||
|
||||
static void (* curses_action [SIGNAL_COUNT]) (void) = { 0 };
|
||||
|
||||
static struct termios curses_old_terminal;
|
||||
@ -45,23 +48,21 @@ static void curses_free (void) {
|
||||
|
||||
/* Return offset of variable 'curses_screen' according to X and Y coordinates. */
|
||||
static char * curses_screen_offset (int x, int y) {
|
||||
log_in (LOG_FAILURE, x <= -1, "curses_screen_offset: X position is below the lower bound.");
|
||||
/*log_in (LOG_FAILURE, x <= -1, "curses_screen_offset: X position is below the lower bound.");
|
||||
log_in (LOG_FAILURE, y <= -1, "curses_screen_offset: Y position is below the lower bound.");
|
||||
log_in (LOG_FAILURE, x >= curses_screen_width, "curses_screen_offset: X position is above the upper bound.");
|
||||
log_in (LOG_FAILURE, y >= curses_screen_height, "curses_screen_offset: Y position is above the upper bound.");
|
||||
log_in (LOG_FAILURE, y >= curses_screen_height, "curses_screen_offset: Y position is above the upper bound.");*/
|
||||
|
||||
limit (& x, 0, curses_screen_width - 1);
|
||||
limit (& y, 0, curses_screen_height - 1);
|
||||
|
||||
return (& curses_screen [CURSES_REVERT + CURSES_OFFSET * (y * curses_screen_width + x)]);
|
||||
return (& curses_screen [CURSES_REVERT + CURSES_FORMAT * (y * curses_screen_width + x)]);
|
||||
}
|
||||
|
||||
static char * curses_format_character (char character, int colour, int effect) {
|
||||
static char curses_format [CURSES_OFFSET + 1] = "\033[-;3-m-\033[0m";
|
||||
|
||||
log_in (LOG_WARNING, character_is_invisible (character), "curses_format_character: Can not format invisible characters.");
|
||||
/*log_in (LOG_WARNING, character_is_invisible (character), "curses_format_character: Can not format invisible characters.");
|
||||
log_in (LOG_FAILURE, colour >= COLOUR_COUNT, "curses_format_character: Colour is invalid enumeration value.");
|
||||
log_in (LOG_FAILURE, effect >= EFFECT_COUNT, "curses_format_character: Effect is invalid enumeration value.");
|
||||
log_in (LOG_FAILURE, effect >= EFFECT_COUNT, "curses_format_character: Effect is invalid enumeration value.");*/
|
||||
|
||||
if (character_is_invisible (character) != 0) {
|
||||
character = ' ';
|
||||
@ -71,7 +72,7 @@ static char * curses_format_character (char character, int colour, int effect) {
|
||||
curses_format [5] = (char) (colour % COLOUR_COUNT) + '0';
|
||||
curses_format [7] = character;
|
||||
|
||||
log_out ("curses.log");
|
||||
/*log_out ("curses.log");*/
|
||||
|
||||
return (curses_format);
|
||||
}
|
||||
@ -112,7 +113,7 @@ void curses_configure (void) {
|
||||
|
||||
fatal_failure (tcsetattr (STDIN_FILENO, TCSAFLUSH, & curses_new_terminal) == -1, "tcsetattr: Failed to set reverse terminal attributes.");
|
||||
|
||||
curses_screen = allocate (CURSES_REVERT + CURSES_OFFSET * curses_screen_width * curses_screen_height + 1);
|
||||
curses_screen = allocate (CURSES_REVERT + CURSES_FORMAT * curses_screen_width * curses_screen_height + CURSES_CURSOR + 1);
|
||||
|
||||
for (signal = SIGNAL_NONE; signal != SIGNAL_COUNT; ++signal) {
|
||||
curses_unbind ((char) signal);
|
||||
@ -126,7 +127,7 @@ void curses_configure (void) {
|
||||
void curses_synchronize (void) {
|
||||
curses_signal = '\0';
|
||||
|
||||
out (curses_screen, CURSES_REVERT + CURSES_OFFSET * curses_screen_width * curses_screen_height);
|
||||
out (curses_screen, CURSES_REVERT + CURSES_FORMAT * curses_screen_width * curses_screen_height);
|
||||
|
||||
in (& curses_signal, 4);
|
||||
|
||||
@ -152,8 +153,20 @@ void curses_synchronize (void) {
|
||||
}
|
||||
}
|
||||
|
||||
void curses_bind (int signal, void (* action) (void)) {
|
||||
curses_action [signal] = action;
|
||||
}
|
||||
|
||||
void curses_unbind (int signal) {
|
||||
curses_action [signal] = curses_idle;
|
||||
}
|
||||
|
||||
void curses_render_cursor (int x, int y) {
|
||||
terminal_show_cursor (x + y);
|
||||
}
|
||||
|
||||
void curses_render_character (char character, int colour, int effect, int x, int y) {
|
||||
string_copy_limit (curses_screen_offset (x, y), curses_format_character (character, colour, effect), CURSES_OFFSET);
|
||||
string_copy_limit (curses_screen_offset (x, y), curses_format_character (character, colour, effect), CURSES_FORMAT);
|
||||
}
|
||||
|
||||
void curses_render_background (char character, int colour, int effect) {
|
||||
@ -166,12 +179,35 @@ void curses_render_background (char character, int colour, int effect) {
|
||||
}
|
||||
}
|
||||
|
||||
void curses_bind (int signal, void (* action) (void)) {
|
||||
curses_action [signal] = action;
|
||||
void curses_render_string_limit (char * string, int limit, int colour, int effect, int x, int y) {
|
||||
int offset;
|
||||
|
||||
for (offset = 0; offset != limit; ++offset) {
|
||||
if (x + offset < curses_screen_width) {
|
||||
curses_render_character (string [offset], colour, effect, x + offset, y);
|
||||
} else {
|
||||
curses_render_character ('+', COLOUR_GREY, EFFECT_BOLD, x + offset, y);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void curses_unbind (int signal) {
|
||||
curses_action [signal] = curses_idle;
|
||||
void curses_render_number_limit (int number, int limit, int colour, int effect, int x, int y) {
|
||||
(void) number;
|
||||
(void) limit;
|
||||
(void) colour;
|
||||
(void) effect;
|
||||
(void) x;
|
||||
(void) y;
|
||||
return;
|
||||
}
|
||||
|
||||
void curses_render_string (char * string, int colour, int effect, int x, int y) {
|
||||
curses_render_string_limit (string, string_length (string), colour, effect, x, y);
|
||||
}
|
||||
|
||||
void curses_render_number (int number, int colour, int effect, int x, int y) {
|
||||
curses_render_number_limit (number, 4, colour, effect, x, y);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
9
xurses.h
9
xurses.h
@ -18,9 +18,16 @@ extern void curses_synchronize (void);
|
||||
|
||||
extern void curses_bind (int signal, void (* action) (void));
|
||||
extern void curses_unbind (int signal);
|
||||
extern void curses_exit (int signal);
|
||||
|
||||
extern void curses_render_cursor (int x, int y);
|
||||
|
||||
extern void curses_render_character (char character, int colour, int effect, int x, int y);
|
||||
extern void curses_render_background (char character, int colour, int effect);
|
||||
|
||||
extern void curses_render_string_limit (char * string, int limit, int colour, int effect, int x, int y);
|
||||
extern void curses_render_number_limit (int number, int limit, int colour, int effect, int x, int y);
|
||||
|
||||
extern void curses_render_string (char * string, int colour, int effect, int x, int y);
|
||||
extern void curses_render_number (int number, int colour, int effect, int x, int y);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user