The saved attributes could potentially get out of sync.

This commit is contained in:
William McBrine
2018-02-05 08:50:39 -05:00
parent 18464b0527
commit be0b880b33
3 changed files with 18 additions and 9 deletions

View File

@@ -83,9 +83,6 @@ void PDC_gotoyx(int row, int col)
void _set_ansi_color(short f, short b, attr_t attr)
{
char esc[64], *p;
static short oldf = -1;
static short oldb = -1;
static short oldu = 0;
short tmp, underline;
if (f < 16)
@@ -104,7 +101,7 @@ void _set_ansi_color(short f, short b, attr_t attr)
p = esc + sprintf(esc, "\x1b[");
if (f != oldf)
if (f != pdc_oldf)
{
if (f < 8)
p += sprintf(p, "%d", f + 30);
@@ -113,10 +110,10 @@ void _set_ansi_color(short f, short b, attr_t attr)
else
p += sprintf(p, "38;5;%d", f);
oldf = f;
pdc_oldf = f;
}
if (b != oldb)
if (b != pdc_oldb)
{
if (strlen(esc) > 2)
p += sprintf(p, ";");
@@ -128,10 +125,10 @@ void _set_ansi_color(short f, short b, attr_t attr)
else
p += sprintf(p, "48;5;%d", b);
oldb = b;
pdc_oldb = b;
}
if (underline != oldu)
if (underline != pdc_oldu)
{
if (strlen(esc) > 2)
p += sprintf(p, ";");
@@ -141,7 +138,7 @@ void _set_ansi_color(short f, short b, attr_t attr)
else
p += sprintf(p, "24");
oldu = underline;
pdc_oldu = underline;
}
if (strlen(esc) > 2)

View File

@@ -31,6 +31,7 @@ static short ansitocurs[16] =
};
short pdc_curstoreal[16], pdc_curstoansi[16];
short pdc_oldf, pdc_oldb, pdc_oldu;
enum { PDC_RESTORE_NONE, PDC_RESTORE_BUFFER };
@@ -88,6 +89,13 @@ static DWORD old_console_mode = 0;
static bool is_nt;
static void _reset_old_colors(void)
{
pdc_oldf = -1;
pdc_oldb = -1;
pdc_oldu = 0;
}
static HWND _find_console_handle(void)
{
TCHAR orgtitle[1024], temptitle[1024];
@@ -184,6 +192,8 @@ static int _set_console_infoex(void)
static int _set_colors(void)
{
SetConsoleTextAttribute(pdc_con_out, 7);
_reset_old_colors();
if (pSetConsoleScreenBufferInfoEx)
return _set_console_infoex();
else
@@ -368,6 +378,7 @@ int PDC_scr_open(int argc, char **argv)
pdc_curstoreal[realtocurs[i]] = i;
pdc_curstoansi[ansitocurs[i]] = i;
}
_reset_old_colors();
std_con_out =
pdc_con_out = GetStdHandle(STD_OUTPUT_HANDLE);

View File

@@ -17,6 +17,7 @@ extern HANDLE pdc_con_out, pdc_con_in;
extern DWORD pdc_quick_edit;
extern DWORD pdc_last_blink;
extern short pdc_curstoreal[16], pdc_curstoansi[16];
extern short pdc_oldf, pdc_oldb, pdc_oldu;
extern int PDC_get_buffer_rows(void);
extern void PDC_blink_text(void);