Skip to content

Commit 57c6793

Browse files
committed
Manual Merge change 3d38805
ID Author Date Message 3d38805 Ray Hayes <[email protected]> 9/20/2016 11:11:06 AM -07:00 Minor fixes for color handling and newline handling.
1 parent 3e23785 commit 57c6793

File tree

2 files changed

+42
-11
lines changed

2 files changed

+42
-11
lines changed

contrib/win32/win32compat/ansiprsr.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ unsigned char* ParseBuffer(unsigned char* pszBuffer, unsigned char* pszBufferEnd
250250
case 10:
251251
pszBuffer++;
252252
AutoWrap = 1;
253-
bAtEOLN = TRUE;
254-
break;
253+
GoToNextLine();
254+
break;
255255

256256
case 12:
257257
pszBuffer++;
@@ -510,6 +510,8 @@ unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEn
510510
else if (bMode & MODE_BRK)
511511
{
512512
// Cursor UP
513+
if (iParam[0] == 0)
514+
iParam[0] = 1;
513515
ConMoveCursorPosition(0, -iParam[0]);
514516
}
515517
fcompletion = 1;
@@ -523,6 +525,8 @@ unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEn
523525
else if (bMode & MODE_BRK)
524526
{
525527
// Cursor DOWN
528+
if (iParam[0] == 0)
529+
iParam[0] = 1;
526530
ConMoveCursorPosition(0, iParam[0]);
527531
}
528532
fcompletion = 1;
@@ -536,6 +540,8 @@ unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEn
536540
else if (bMode & MODE_BRK)
537541
{
538542
// Cursor right
543+
if (iParam[0] == 0)
544+
iParam[0] = 1;
539545
ConMoveCursorPosition(iParam[0], 0);
540546

541547
}
@@ -863,7 +869,7 @@ unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEn
863869
bCS1 = 0;
864870
bBkMode = 0;
865871
bCharMode = 0;
866-
return pszCurrent;
872+
return pszCurrent;
867873
}
868874
else
869875
return pszBuffer;
@@ -906,9 +912,9 @@ unsigned char * ParseVT52(unsigned char * pszBuffer, unsigned char * pszBufferEn
906912
break;
907913

908914
case 'H': // Cursor Home
909-
ConSetCursorPosition(1, 1);
915+
ConSetCursorPosition(0, 0);
910916
pszCurrent++;
911-
bAtEOLN = FALSE;
917+
bAtEOLN = FALSE;
912918
break;
913919
case 'I': // Reverse Line Feed
914920
pszCurrent++;

contrib/win32/win32compat/console.c

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,12 @@ int ConInit( DWORD OutputHandle, BOOL fSmartInit )
104104

105105
if ( os.dwPlatformId == VER_PLATFORM_WIN32_NT )
106106
{
107-
dwAttributes = (DWORD)ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING; // PERFECT in NT
107+
char *term = getenv("TERM");
108+
dwAttributes = (DWORD)ENABLE_PROCESSED_OUTPUT; // PERFECT in NT
109+
110+
if (term != NULL && (_stricmp(term, "ansi") == 0 || _stricmp(term, "passthru")))
111+
dwAttributes |= (DWORD)ENABLE_VIRTUAL_TERMINAL_PROCESSING;
112+
108113
SetConsoleMode(hOutputConsole, dwAttributes); // Windows NT
109114
}
110115
else
@@ -285,19 +290,34 @@ BOOL ConSetScreenSize( int xSize, int ySize )
285290
/* ************************************************************ */
286291
void ConSetAttribute(int *iParam, int iParamCount)
287292
{
288-
int iAttr = 0;
293+
static int iAttr = 0;
289294
int i = 0;
295+
BOOL bRet = TRUE;
290296

291297
if (iParamCount < 1)
292-
SetConsoleTextAttribute(hOutputConsole, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
298+
{
299+
iAttr |= FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
300+
301+
iAttr = iAttr & ~BACKGROUND_INTENSITY;
302+
iAttr = iAttr & ~FOREGROUND_INTENSITY;
303+
iAttr = iAttr & ~COMMON_LVB_UNDERSCORE;
304+
iAttr = iAttr & ~COMMON_LVB_REVERSE_VIDEO;
305+
306+
SetConsoleTextAttribute(hOutputConsole, (WORD)iAttr);
307+
}
293308
else
294309
{
295310
for (i=0;i<iParamCount;i++)
296311
{
297312
switch (iParam[i])
298313
{
299314
case ANSI_ATTR_RESET:
300-
SetConsoleTextAttribute(hOutputConsole, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
315+
iAttr |= FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
316+
317+
iAttr = iAttr & ~BACKGROUND_INTENSITY;
318+
iAttr = iAttr & ~FOREGROUND_INTENSITY;
319+
iAttr = iAttr & ~COMMON_LVB_UNDERSCORE;
320+
iAttr = iAttr & ~COMMON_LVB_REVERSE_VIDEO;
301321
break;
302322
case ANSI_BRIGHT:
303323
iAttr |= FOREGROUND_INTENSITY;
@@ -315,7 +335,7 @@ void ConSetAttribute(int *iParam, int iParamCount)
315335
case ANSI_HIDDEN:
316336
break;
317337
case ANSI_NOREVERSE:
318-
iAttr |= FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
338+
iAttr = iAttr & ~COMMON_LVB_REVERSE_VIDEO;
319339
break;
320340
case ANSI_DEFAULT_FOREGROUND:
321341
// White
@@ -359,6 +379,9 @@ void ConSetAttribute(int *iParam, int iParamCount)
359379
break;
360380
case ANSI_DEFAULT_BACKGROUND:
361381
//Black
382+
iAttr = iAttr & ~BACKGROUND_RED;
383+
iAttr = iAttr & ~BACKGROUND_BLUE;
384+
iAttr = iAttr & ~BACKGROUND_GREEN;
362385
iAttr |= 0;
363386
break;
364387
case ANSI_BACKGROUND_BLACK:
@@ -400,11 +423,13 @@ void ConSetAttribute(int *iParam, int iParamCount)
400423
case ANSI_BACKGROUND_BRIGHT:
401424
iAttr |= BACKGROUND_INTENSITY;
402425
break;
426+
default:
427+
continue;
403428
}
404429
}
405430

406431
if (iAttr)
407-
SetConsoleTextAttribute(hOutputConsole, (WORD)iAttr);
432+
bRet = SetConsoleTextAttribute(hOutputConsole, (WORD)iAttr);
408433
}
409434
} // End procedure
410435

0 commit comments

Comments
 (0)