/* ================= Sys_AnsiColorPrint Transform Q3 colour codes to ANSI escape sequences ================= */ void Sys_AnsiColorPrint( const char *msg ) { static char buffer[MAXPRINTMSG]; int length = 0; static int q3ToAnsi[Q_COLOR_BITS+1] = { 30, // COLOR_BLACK 31, // COLOR_RED 32, // COLOR_GREEN 33, // COLOR_YELLOW 34, // COLOR_BLUE 36, // COLOR_CYAN 35, // COLOR_MAGENTA 0, // COLOR_WHITE 33, // COLOR_ORANGE // FIXME 30, // COLOR_GREY }; while ( *msg ) { if ( Q_IsColorStringExt( msg ) || *msg == '\n' ) { // First empty the buffer if ( length > 0 ) { buffer[length] = '\0'; fputs( buffer, stderr ); length = 0; } if ( *msg == '\n' ) { // Issue a reset and then the newline fputs( "\033[0m\n", stderr ); msg++; } else { // Print the color code Com_sprintf( buffer, sizeof( buffer ), "\033[%dm", q3ToAnsi[ColorIndex( *(msg + 1) )] ); fputs( buffer, stderr ); msg += 2; } } else { if ( length >= MAXPRINTMSG - 1 ) break; buffer[length] = *msg; length++; msg++; } } // Empty anything still left in the buffer if ( length > 0 ) { buffer[length] = '\0'; fputs( buffer, stderr ); } }
/* ** Conbuf_AppendText */ void Conbuf_AppendText( const char *pMsg ) { #define CONSOLE_BUFFER_SIZE 16384 if ( !s_wcd.hWnd ) { return; } char buffer[CONSOLE_BUFFER_SIZE*4]; char *b = buffer; const char *msg; int bufLen; int i = 0; static unsigned long s_totalChars; // // if the message is REALLY long, use just the last portion of it // if ( strlen( pMsg ) > CONSOLE_BUFFER_SIZE - 1 ) { msg = pMsg + strlen( pMsg ) - CONSOLE_BUFFER_SIZE + 1; } else { msg = pMsg; } // // copy into an intermediate buffer // while ( msg[i] && ( ( b - buffer ) < sizeof( buffer ) - 1 ) ) { if ( msg[i] == '\n' && msg[i+1] == '\r' ) { b[0] = '\r'; b[1] = '\n'; b += 2; i++; } else if ( msg[i] == '\r' ) { b[0] = '\r'; b[1] = '\n'; b += 2; } else if ( msg[i] == '\n' ) { b[0] = '\r'; b[1] = '\n'; b += 2; } else if ( Q_IsColorStringExt( &msg[i] ) ) { i++; } else { *b= msg[i]; b++; } i++; } *b = 0; bufLen = b - buffer; s_totalChars += bufLen; // // replace selection instead of appending if we're overflowing // if ( s_totalChars > 0x7fff ) { SendMessage( s_wcd.hwndBuffer, EM_SETSEL, 0, -1 ); s_totalChars = bufLen; } // // put this text into the windows console // SendMessage( s_wcd.hwndBuffer, EM_LINESCROLL, 0, 0xffff ); SendMessage( s_wcd.hwndBuffer, EM_SCROLLCARET, 0, 0 ); SendMessage( s_wcd.hwndBuffer, EM_REPLACESEL, 0, (LPARAM) buffer ); }