Skip to content
Snippets Groups Projects
Commit 9286ce0b authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Support terminals that don't allow disabling attributes.

Both Telemate v4.20 and Qmodem v4.6 don't support these, and Synchronet
supports both of those.

Instead of using the 22, 24, 25, 27, or 28 SGR parameters, always
use the 0 parameter to turn HIGH, UNDERLINE, BLINK, REVERSED, or
CONCEALED (respectively) off.

Fixes issues #934 and #935
parent 99c1ec3f
No related branches found
No related tags found
No related merge requests found
Pipeline #8987 failed
...@@ -107,6 +107,7 @@ const char *ANSI_Terminal::attrstr(unsigned atr) ...@@ -107,6 +107,7 @@ const char *ANSI_Terminal::attrstr(unsigned atr)
return "-Invalid use of ansi()-"; return "-Invalid use of ansi()-";
} }
#if 0 // Used by disabled telemate/qmodem code below
static uint32_t static uint32_t
popcnt(const uint32_t val) popcnt(const uint32_t val)
{ {
...@@ -119,6 +120,7 @@ popcnt(const uint32_t val) ...@@ -119,6 +120,7 @@ popcnt(const uint32_t val)
i *= 0x01010101; i *= 0x01010101;
return i >> 24; return i >> 24;
} }
#endif
// Was ansi() and ansi_attr() // Was ansi() and ansi_attr()
char* ANSI_Terminal::attrstr(unsigned atr, unsigned curatr, char* str, size_t strsz) char* ANSI_Terminal::attrstr(unsigned atr, unsigned curatr, char* str, size_t strsz)
...@@ -165,8 +167,10 @@ char* ANSI_Terminal::attrstr(unsigned atr, unsigned curatr, char* str, size_t st ...@@ -165,8 +167,10 @@ char* ANSI_Terminal::attrstr(unsigned atr, unsigned curatr, char* str, size_t st
} }
lastret = strlcpy(str, "\033[", strsz); lastret = strlcpy(str, "\033[", strsz);
// Not supported by Telemate or Qmodem, which we do support
#if 0
uint32_t changed_mask = (curatr ^ atr) & (HIGH | BLINK | REVERSED | UNDERLINE | CONCEALED); uint32_t changed_mask = (curatr ^ atr) & (HIGH | BLINK | REVERSED | UNDERLINE | CONCEALED);
// TODO: CSI 0 m does *NOT* set
if (changed_mask) { if (changed_mask) {
uint32_t set = popcnt(changed_mask & atr); uint32_t set = popcnt(changed_mask & atr);
uint32_t clear = popcnt(changed_mask & ~atr); uint32_t clear = popcnt(changed_mask & ~atr);
...@@ -187,10 +191,24 @@ char* ANSI_Terminal::attrstr(unsigned atr, unsigned curatr, char* str, size_t st ...@@ -187,10 +191,24 @@ char* ANSI_Terminal::attrstr(unsigned atr, unsigned curatr, char* str, size_t st
if (set_only_weight < set_clear_weight) { if (set_only_weight < set_clear_weight) {
lastret = strlcat(str, "0;", strsz); lastret = strlcat(str, "0;", strsz);
curatr &= ~0x77; curatr &= ~(0x77 | HIGH | BLINK | REVERSED | UNDERLINE | CONCEALED);
curatr |= ANSI_NORMAL; curatr |= ANSI_NORMAL;
} }
} }
#else
// TODO: Detect or configure this.
// If turning off any of the special bits, reset
// to normal rather than use the turn off code.
if (((!(atr & HIGH)) && (curatr & HIGH)) ||
((!(atr & BLINK)) && (curatr & BLINK)) ||
((!(atr & REVERSED)) && (curatr & REVERSED)) ||
((!(atr & UNDERLINE)) && (curatr & UNDERLINE)) ||
((!(atr & CONCEALED)) && (curatr & CONCEALED))) {
lastret = strlcat(str, "0;", strsz);
curatr &= ~(0x77 | HIGH | BLINK | REVERSED | UNDERLINE | CONCEALED);
curatr |= ANSI_NORMAL;
}
#endif
if (atr & HIGH) { /* special attributes */ if (atr & HIGH) { /* special attributes */
if (!(curatr & HIGH)) if (!(curatr & HIGH))
lastret = strlcat(str, "1;", strsz); lastret = strlcat(str, "1;", strsz);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment