petattr: Change accepted parameters, add support for tty

This commit is contained in:
Pasi Kallinen
2024-01-28 10:05:35 +02:00
parent bac8ebad34
commit fd8b2b58d1
8 changed files with 57 additions and 151 deletions

View File

@@ -909,7 +909,7 @@ curses_print_glyph(
ch = glyphinfo->ttychar;
color = glyphinfo->gm.sym.color;
if ((special & MG_PET) && iflags.hilite_pet) {
attr = iflags.wc2_petattr;
attr = curses_convert_attr(iflags.wc2_petattr);
}
if ((special & MG_DETECT) && iflags.use_inverse) {
attr = A_REVERSE;

View File

@@ -768,92 +768,8 @@ curses_convert_attr(int attr)
return curses_attr;
}
/* Map letter attributes from a string to bitmask. Return mask on
success (might be 0), or -1 if not found. */
int
curses_read_attrs(const char *attrs)
{
int retattr = 0;
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 |= A_ITALIC;
#endif
#ifdef 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(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. */
int
curses_convert_keys(int key)
{