curses run-time options

This started out as an attempt to document the curses options in the
Guidebook, but I didn't actually get that far.  Instead, integrate
the curses options better via more consistent WC/WC2 usage.  This
prevents 'guicolor' from showing up as a boolean option for non-curses
interface in curses+other binary.

For curses itself, let 'petattr' be set/reset via 'O'.  Also, accept
'Dim' as a possible pet highlight attribute since it already handles
all the other ordinary attributes.  I'm not sure what leftline and
rightline highlighting are supposed to do.  They were missing for
ncurses (or maybe they're misspelled for PDcurses?) but adding them
didn't produce any visible effect (using TERM=xterm-256color on OSX
with default font/character set).

Not addressed:
1) general confusion about compile-time vs run-time option filtering;
2) curses pet highlighting only works if 'color' option is enabled.
This commit is contained in:
PatR
2019-02-26 15:16:42 -08:00
parent 5a432d0c97
commit 1a028d1197
5 changed files with 178 additions and 89 deletions
+8 -4
View File
@@ -835,11 +835,15 @@ curses_init_options()
iflags.wc2_windowborders = 3; /* Set to auto if not specified */
}
if (!iflags.wc2_petattr) {
iflags.wc2_petattr = A_REVERSE;
} else { /* Pet attribute specified, so hilite_pet should be true */
/* fix up pet highlighting */
if (iflags.wc2_petattr == -1) /* shouldn't happen */
iflags.wc2_petattr = A_NORMAL;
if (iflags.wc2_petattr != A_NORMAL) {
/* Pet attribute specified, so hilite_pet should be true */
iflags.hilite_pet = TRUE;
} else if (iflags.hilite_pet) {
/* pet highlighting specified, so don't leave petattr at A_NORMAL */
iflags.wc2_petattr = A_REVERSE;
}
#ifdef NCURSES_MOUSE_VERSION
+74 -31
View File
@@ -47,7 +47,7 @@ curses_read_char()
ch = curses_convert_keys(ch);
if (ch == 0) {
ch = '\033'; /* map NUL to ESC since nethack doesn't expect NUL */
ch = '\033'; /* map NUL to ESC since nethack doesn't expect NUL */
}
#if defined(ALT_0) && defined(ALT_9) /* PDCurses, maybe others */
if ((ch >= ALT_0) && (ch <= ALT_9)) {
@@ -66,11 +66,11 @@ curses_read_char()
#ifdef KEY_RESIZE
/* Handle resize events via get_nh_event, not this code */
if (ch == KEY_RESIZE) {
ch = '\033'; /* NetHack doesn't know what to do with KEY_RESIZE */
ch = '\033'; /* NetHack doesn't know what to do with KEY_RESIZE */
}
#endif
if (counting && !isdigit(ch)) { /* Dismiss count window if necissary */
if (counting && !isdigit(ch)) { /* Dismiss count window if necissary */
curses_count_window(NULL);
curses_refresh_nethack_windows();
}
@@ -249,7 +249,7 @@ curses_num_lines(const char *str, int width)
if (last_space == 0) { /* No spaces found */
last_space = count - 1;
}
for (count = (last_space + 1); (size_t) count < strlen(substr); count++) {
for (count = (last_space + 1); count < (int) strlen(substr); count++) {
tmpstr[count - (last_space + 1)] = substr[count];
}
tmpstr[count - (last_space + 1)] = '\0';
@@ -389,7 +389,7 @@ curses_str_remainder(const char *str, int width, int line_num)
if (substr[count] == '\0') {
break;
}
for (count = (last_space + 1); (size_t) count < strlen(substr); count++) {
for (count = (last_space + 1); count < (int) strlen(substr); count++) {
tmpstr[count - (last_space + 1)] = substr[count];
}
tmpstr[count - (last_space + 1)] = '\0';
@@ -682,44 +682,87 @@ curses_convert_attr(int attr)
/* Map letter attributes from a string to bitmask. Return mask on
success, or 0 if not found */
success (might be 0), or -1 if not found. */
int
curses_read_attrs(char *attrs)
{
int retattr = 0;
if (strchr(attrs, 'b') || strchr(attrs, 'B')) {
retattr = retattr | A_BOLD;
}
if (strchr(attrs, 'i') || strchr(attrs, 'I')) {
retattr = retattr | A_REVERSE;
}
if (strchr(attrs, 'u') || strchr(attrs, 'U')) {
retattr = retattr | A_UNDERLINE;
}
if (strchr(attrs, 'k') || strchr(attrs, 'K')) {
retattr = retattr | A_BLINK;
}
if (!attrs || !*attrs)
return A_NORMAL;
if (strchr(attrs, 'b') || strchr(attrs, 'B'))
retattr |= A_BOLD;
if (strchr(attrs, 'i') || strchr(attrs, 'I')) /* inverse */
retattr |= A_REVERSE;
if (strchr(attrs, 'u') || strchr(attrs, 'U'))
retattr |= A_UNDERLINE;
if (strchr(attrs, 'k') || strchr(attrs, 'K'))
retattr |= A_BLINK;
if (strchr(attrs, 'd') || strchr(attrs, 'D'))
retattr |= A_DIM;
#ifdef A_ITALIC
if (strchr(attrs, 't') || strchr(attrs, 'T')) {
retattr = retattr | A_ITALIC;
}
#endif
#ifdef A_RIGHTLINE
if (strchr(attrs, 'r') || strchr(attrs, 'R')) {
retattr = retattr | A_RIGHTLINE;
}
if (strchr(attrs, 't') || strchr(attrs, 'T'))
retattr |= A_ITALIC;
#endif
#ifdef A_LEFTLINE
if (strchr(attrs, 'l') || strchr(attrs, 'L')) {
retattr = retattr | A_LEFTLINE;
}
if (strchr(attrs, 'l') || strchr(attrs, 'L'))
retattr |= A_LEFTLINE;
#endif
#ifdef A_RIGHTLINE
if (strchr(attrs, 'r') || strchr(attrs, 'R'))
retattr |= A_RIGHTLINE;
#endif
if (retattr == 0) {
/* still default; check for none/normal */
if (strchr(attrs, 'n') || strchr(attrs, 'N'))
retattr = A_NORMAL;
else
retattr = -1; /* error */
}
return retattr;
}
/* format iflags.wc2_petattr into "+a+b..." for set bits a, b, ...
(used by core's 'O' command; return value points past leading '+') */
char *
curses_fmt_attrs(outbuf)
char *outbuf;
{
int attr = iflags.wc2_petattr;
outbuf[0] = '\0';
if (attr == A_NORMAL) {
Strcpy(outbuf, "+N(None)");
} else {
if (attr & A_BOLD)
Strcat(outbuf, "+B(Bold)");
if (attr & A_REVERSE)
Strcat(outbuf, "+I(Inverse)");
if (attr & A_UNDERLINE)
Strcat(outbuf, "+U(Underline)");
if (attr & A_BLINK)
Strcat(outbuf, "+K(blinK)");
if (attr & A_DIM)
Strcat(outbuf, "+D(Dim)");
#ifdef A_ITALIC
if (attr & A_ITALIC)
Strcat(outbuf, "+T(iTalic)");
#endif
#ifdef A_LEFTLINE
if (attr & A_LEFTLINE)
Strcat(outbuf, "+L(Left line)");
#endif
#ifdef A_RIGHTLINE
if (attr & A_RIGHTLINE)
Strcat(outbuf, "+R(Right line)");
#endif
}
if (!*outbuf)
Sprintf(outbuf, "+unknown [%d]", attr);
return &outbuf[1];
}
/* Convert special keys into values that NetHack can understand.
Currently this is limited to arrow keys, but this may be expanded. */
@@ -827,7 +870,7 @@ curses_get_mouse(int *mousex, int *mousey, int *mod)
#ifdef NCURSES_MOUSE_VERSION
MEVENT event;
if (getmouse(&event) == OK) { /* When the user clicks left mouse button */
if (getmouse(&event) == OK) { /* When the user clicks left mouse button */
if (event.bstate & BUTTON1_CLICKED) {
/* See if coords are in map window & convert coords */
if (wmouse_trafo(mapwin, &event.y, &event.x, TRUE)) {
+1
View File
@@ -27,6 +27,7 @@ void curses_rtrim(char *str);
int curses_get_count(int first_digit);
int curses_convert_attr(int attr);
int curses_read_attrs(char *attrs);
char *curses_fmt_attrs(char *);
int curses_convert_keys(int key);
int curses_get_mouse(int *mousex, int *mousey, int *mod);