mirror of
https://git.zap.org.au/git/trader.git
synced 2024-12-04 14:46:45 -05:00
Add input routines gettxchar() and getanswer(); add various macros
In particular, add macros for KEY_TAB, KEY_RETURN and KEY_ESC, and for CURS_ON and CURS_OFF (instead of using CURS_INVISIBLE and CURS_VISIBLE directly: this allows redefining CURS_ON to be CURS_NORMAL). Add more colour pairs.
This commit is contained in:
parent
568c3738b2
commit
ad4ed4d744
91
src/intf.c
91
src/intf.c
@ -66,7 +66,6 @@ txwin_t *firstwin = NULL; // First (bottom-most) txwin structure
|
|||||||
* Basic text input/output function definitions *
|
* Basic text input/output function definitions *
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------
|
/*-----------------------------------------------------------------------
|
||||||
Function: init_screen - Initialise the screen (terminal)
|
Function: init_screen - Initialise the screen (terminal)
|
||||||
Arguments: (none)
|
Arguments: (none)
|
||||||
@ -90,17 +89,19 @@ void init_screen (void)
|
|||||||
firstwin = NULL;
|
firstwin = NULL;
|
||||||
|
|
||||||
noecho();
|
noecho();
|
||||||
curs_set(CURS_INVISIBLE);
|
curs_set(CURS_OFF);
|
||||||
raw();
|
raw();
|
||||||
|
|
||||||
if (has_colors()) {
|
if (has_colors()) {
|
||||||
start_color();
|
start_color();
|
||||||
|
|
||||||
init_pair(WHITE_ON_BLACK, COLOR_WHITE, COLOR_BLACK);
|
init_pair(WHITE_ON_BLACK, COLOR_WHITE, COLOR_BLACK);
|
||||||
init_pair(WHITE_ON_BLUE, COLOR_WHITE, COLOR_BLUE);
|
init_pair(WHITE_ON_BLUE, COLOR_WHITE, COLOR_BLUE);
|
||||||
init_pair(YELLOW_ON_CYAN, COLOR_YELLOW, COLOR_CYAN);
|
init_pair(WHITE_ON_RED, COLOR_WHITE, COLOR_RED);
|
||||||
init_pair(WHITE_ON_RED, COLOR_WHITE, COLOR_RED);
|
init_pair(YELLOW_ON_BLACK, COLOR_YELLOW, COLOR_BLACK);
|
||||||
init_pair(BLACK_ON_WHITE, COLOR_BLACK, COLOR_WHITE);
|
init_pair(YELLOW_ON_BLUE, COLOR_YELLOW, COLOR_BLUE);
|
||||||
|
init_pair(YELLOW_ON_CYAN, COLOR_YELLOW, COLOR_CYAN);
|
||||||
|
init_pair(BLACK_ON_WHITE, COLOR_BLACK, COLOR_WHITE);
|
||||||
|
|
||||||
bkgd(COLOR_PAIR(WHITE_ON_BLACK));
|
bkgd(COLOR_PAIR(WHITE_ON_BLACK));
|
||||||
}
|
}
|
||||||
@ -136,6 +137,10 @@ void end_screen (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Simplified panel-like window functions *
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------
|
/*-----------------------------------------------------------------------
|
||||||
Function: newtxwin - Create a new window, inserted into window stack
|
Function: newtxwin - Create a new window, inserted into window stack
|
||||||
Arguments: nlines - Number of lines in new window
|
Arguments: nlines - Number of lines in new window
|
||||||
@ -277,6 +282,10 @@ int txrefresh (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Output routines *
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------
|
/*-----------------------------------------------------------------------
|
||||||
Function: center - Centre a string on the current line
|
Function: center - Centre a string on the current line
|
||||||
Arguments: win - Window to use
|
Arguments: win - Window to use
|
||||||
@ -370,3 +379,71 @@ int attrpr (WINDOW *win, int attr_start, int attr_end, const char *format, ...)
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Input routines *
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------
|
||||||
|
Function: gettxchar - Read a keyboard character
|
||||||
|
Arguments: win - Window to use
|
||||||
|
Returns: int - Keyboard character
|
||||||
|
|
||||||
|
This function reads a single character from the keyboard. The key is
|
||||||
|
NOT echoed to the screen and the cursor visibility is NOT affected.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int gettxchar (WINDOW *win)
|
||||||
|
{
|
||||||
|
keypad(win, true);
|
||||||
|
meta(win, true);
|
||||||
|
wtimeout(win, -1);
|
||||||
|
|
||||||
|
return wgetch(win);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------
|
||||||
|
Function: getanswer - Read a Yes/No answer and return true/false
|
||||||
|
Arguments: win - Window to use
|
||||||
|
Returns: bool - true if Yes ("Y") was selected, else false
|
||||||
|
|
||||||
|
This function waits for either "Y" or "N" to be pressed on the
|
||||||
|
keyboard. If "Y" was pressed, "Yes." is printed and true is returned.
|
||||||
|
If "N" was pressed, "No." is printed and false is returned. Note that
|
||||||
|
the cursor becomes invisible after this function.
|
||||||
|
*/
|
||||||
|
|
||||||
|
bool getanswer (WINDOW *win)
|
||||||
|
{
|
||||||
|
int key;
|
||||||
|
bool ok;
|
||||||
|
|
||||||
|
|
||||||
|
keypad(win, true);
|
||||||
|
meta(win, true);
|
||||||
|
wtimeout(win, -1);
|
||||||
|
|
||||||
|
curs_set(CURS_ON);
|
||||||
|
|
||||||
|
do {
|
||||||
|
key = toupper(wgetch(win));
|
||||||
|
ok = ((key == 'Y') || (key == 'N'));
|
||||||
|
|
||||||
|
if (! ok) {
|
||||||
|
beep();
|
||||||
|
}
|
||||||
|
} while (! ok);
|
||||||
|
|
||||||
|
curs_set(CURS_OFF);
|
||||||
|
|
||||||
|
if (key == 'Y') {
|
||||||
|
wprintw(win, "Yes.");
|
||||||
|
} else {
|
||||||
|
wprintw(win, "No.");
|
||||||
|
}
|
||||||
|
|
||||||
|
wrefresh(win);
|
||||||
|
return (key == 'Y');
|
||||||
|
}
|
||||||
|
16
src/intf.h
16
src/intf.h
@ -46,6 +46,15 @@ typedef enum curs_type {
|
|||||||
CURS_VISIBLE = 2
|
CURS_VISIBLE = 2
|
||||||
} curs_type_t;
|
} curs_type_t;
|
||||||
|
|
||||||
|
#define CURS_OFF (CURS_INVISIBLE)
|
||||||
|
#define CURS_ON (CURS_VISIBLE)
|
||||||
|
|
||||||
|
|
||||||
|
// Keycodes
|
||||||
|
#define KEY_TAB (011)
|
||||||
|
#define KEY_RETURN (012)
|
||||||
|
#define KEY_ESC (033)
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This version of Star Traders only utilises WIN_COLS x WIN_LINES of a
|
This version of Star Traders only utilises WIN_COLS x WIN_LINES of a
|
||||||
@ -74,6 +83,8 @@ enum color_pairs {
|
|||||||
WHITE_ON_BLACK,
|
WHITE_ON_BLACK,
|
||||||
WHITE_ON_BLUE,
|
WHITE_ON_BLUE,
|
||||||
WHITE_ON_RED,
|
WHITE_ON_RED,
|
||||||
|
YELLOW_ON_BLACK,
|
||||||
|
YELLOW_ON_BLUE,
|
||||||
YELLOW_ON_CYAN,
|
YELLOW_ON_CYAN,
|
||||||
BLACK_ON_WHITE,
|
BLACK_ON_WHITE,
|
||||||
};
|
};
|
||||||
@ -110,5 +121,10 @@ extern int attrpr (WINDOW *win, int attr_start, int attr_end,
|
|||||||
const char *format, ...)
|
const char *format, ...)
|
||||||
__attribute__((format (printf, 4, 5)));
|
__attribute__((format (printf, 4, 5)));
|
||||||
|
|
||||||
|
// Input routines
|
||||||
|
|
||||||
|
extern int gettxchar (WINDOW *win);
|
||||||
|
extern bool getanswer (WINDOW *win);
|
||||||
|
|
||||||
|
|
||||||
#endif /* included_INTF_H */
|
#endif /* included_INTF_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user