/* ================== CON_Show ================== */ static void CON_Show( void ) { CONSOLE_SCREEN_BUFFER_INFO binfo; COORD writeSize = { MAX_EDIT_LINE, 1 }; COORD writePos = { 0, 0 }; SMALL_RECT writeArea = { 0, 0, 0, 0 }; COORD cursorPos; int i; CHAR_INFO line[ MAX_EDIT_LINE ]; WORD attrib; GetConsoleScreenBufferInfo( qconsole_hout, &binfo ); // if we're in the middle of printf, don't bother writing the buffer if( !qconsole_drawinput ) return; writeArea.Left = 0; writeArea.Top = binfo.dwCursorPosition.Y; writeArea.Bottom = binfo.dwCursorPosition.Y; writeArea.Right = MAX_EDIT_LINE; // set color to white attrib = CON_ColorCharToAttrib( COLOR_WHITE ); // build a space-padded CHAR_INFO array for( i = 0; i < MAX_EDIT_LINE; i++ ) { if( i < qconsole_linelen ) { if( Q_IsColorString( qconsole_line + i ) ) attrib = CON_ColorCharToAttrib( *( qconsole_line + i + 1 ) ); line[ i ].Char.AsciiChar = qconsole_line[ i ]; } else line[ i ].Char.AsciiChar = ' '; line[ i ].Attributes = attrib; } if( qconsole_linelen > binfo.srWindow.Right ) { WriteConsoleOutput( qconsole_hout, line + (qconsole_linelen - binfo.srWindow.Right ), writeSize, writePos, &writeArea ); } else { WriteConsoleOutput( qconsole_hout, line, writeSize, writePos, &writeArea ); } // set curor position cursorPos.Y = binfo.dwCursorPosition.Y; cursorPos.X = qconsole_linelen > binfo.srWindow.Right ? binfo.srWindow.Right : qconsole_linelen; SetConsoleCursorPosition( qconsole_hout, cursorPos ); }
/* ================= CON_WindowsColorPrint Set text colors based on Q3 color codes ================= */ void CON_WindowsColorPrint(const char *msg) { static char buffer[MAXPRINTMSG]; int length = 0; while (*msg) { qconsole_drawinput = (*msg == '\n'); if (Q_IsColorString(msg) || *msg == '\n') { // First empty the buffer if (length > 0) { buffer[length] = '\0'; fputs(buffer, stderr); length = 0; } if (*msg == '\n') { // Reset color and then add the newline SetConsoleTextAttribute(qconsole_hout, CON_ColorCharToAttrib(COLOR_WHITE)); fputs("\n", stderr); msg++; } else { // Set the color SetConsoleTextAttribute(qconsole_hout, CON_ColorCharToAttrib(*(msg + 1))); 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); } }
/** * @brief CON_Init */ void CON_Init(void) { CONSOLE_CURSOR_INFO curs; CONSOLE_SCREEN_BUFFER_INFO info; int i; // handle Ctrl-C or other console termination SetConsoleCtrlHandler(CON_CtrlHandler, TRUE); qconsole_hin = GetStdHandle(STD_INPUT_HANDLE); if (qconsole_hin == INVALID_HANDLE_VALUE) { return; } qconsole_hout = GetStdHandle(STD_OUTPUT_HANDLE); if (qconsole_hout == INVALID_HANDLE_VALUE) { return; } GetConsoleMode(qconsole_hin, &qconsole_orig_mode); // allow mouse wheel scrolling SetConsoleMode(qconsole_hin, qconsole_orig_mode & ~ENABLE_MOUSE_INPUT); FlushConsoleInputBuffer(qconsole_hin); GetConsoleScreenBufferInfo(qconsole_hout, &info); qconsole_attrib = info.wAttributes; #ifdef DEDICATED SetConsoleTitle(ET_VERSION " Dedicated Server Console"); #else SetConsoleTitle(ET_VERSION " Client Console"); #endif // make cursor invisible GetConsoleCursorInfo(qconsole_hout, &qconsole_orig_cursorinfo); curs.dwSize = 1; curs.bVisible = FALSE; SetConsoleCursorInfo(qconsole_hout, &curs); qconsole_backgroundAttrib = qconsole_attrib & (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY); // initialize history for (i = 0; i < QCONSOLE_HISTORY; i++) { qconsole_history[i][0] = '\0'; } // set text color to white SetConsoleTextAttribute(qconsole_hout, CON_ColorCharToAttrib(COLOR_WHITE)); // set process output translation SetConsoleOutputCP(CP_UTF8); }
/* ================== CON_Init ================== */ void CON_Init( void ) { CONSOLE_SCREEN_BUFFER_INFO info; char consoleTitle[128]; int i; // handle Ctrl-C or other console termination SetConsoleCtrlHandler( CON_CtrlHandler, TRUE ); qconsole_hin = GetStdHandle( STD_INPUT_HANDLE ); if( qconsole_hin == INVALID_HANDLE_VALUE ) return; qconsole_hout = GetStdHandle( STD_OUTPUT_HANDLE ); if( qconsole_hout == INVALID_HANDLE_VALUE ) return; GetConsoleMode( qconsole_hin, &qconsole_orig_mode ); // allow mouse wheel scrolling SetConsoleMode( qconsole_hin, qconsole_orig_mode & ~ENABLE_MOUSE_INPUT ); FlushConsoleInputBuffer( qconsole_hin ); GetConsoleScreenBufferInfo( qconsole_hout, &info ); qconsole_attrib = info.wAttributes; qconsole_backgroundAttrib = qconsole_attrib & (BACKGROUND_BLUE|BACKGROUND_GREEN|BACKGROUND_RED|BACKGROUND_INTENSITY); // ZTM: FIXME: com_productName isn't initialized or set to game title yet. Com_sprintf( consoleTitle, sizeof (consoleTitle), "%s Dedicated Server Console", com_productName ? com_productName->string : PRODUCT_NAME ); SetConsoleTitle( consoleTitle ); // initialize history for( i = 0; i < QCONSOLE_HISTORY; i++ ) qconsole_history[ i ][ 0 ] = '\0'; // set text color to white SetConsoleTextAttribute( qconsole_hout, CON_ColorCharToAttrib( COLOR_WHITE ) ); }
/* ================== CON_Init ================== */ void CON_Init( void ) { CONSOLE_SCREEN_BUFFER_INFO info; int i; // handle Ctrl-C or other console termination SetConsoleCtrlHandler( CON_CtrlHandler, TRUE ); qconsole_hin = GetStdHandle( STD_INPUT_HANDLE ); if( qconsole_hin == INVALID_HANDLE_VALUE ) return; qconsole_hout = GetStdHandle( STD_OUTPUT_HANDLE ); if( qconsole_hout == INVALID_HANDLE_VALUE ) return; GetConsoleMode( qconsole_hin, &qconsole_orig_mode ); // allow mouse wheel scrolling SetConsoleMode( qconsole_hin, qconsole_orig_mode & ~ENABLE_MOUSE_INPUT ); FlushConsoleInputBuffer( qconsole_hin ); GetConsoleScreenBufferInfo( qconsole_hout, &info ); qconsole_attrib = info.wAttributes; qconsole_backgroundAttrib = qconsole_attrib & (BACKGROUND_BLUE|BACKGROUND_GREEN|BACKGROUND_RED|BACKGROUND_INTENSITY); SetConsoleTitle(CLIENT_WINDOW_TITLE " Dedicated Server Console"); // initialize history for( i = 0; i < QCONSOLE_HISTORY; i++ ) qconsole_history[ i ][ 0 ] = '\0'; // set text color to white SetConsoleTextAttribute( qconsole_hout, CON_ColorCharToAttrib( COLOR_WHITE ) ); }
/* ================== CON_Show ================== */ static void CON_Show(void) { CONSOLE_SCREEN_BUFFER_INFO binfo; COORD writeSize = { MAX_EDIT_LINE, 1 }; COORD writePos = { 0, 0 }; SMALL_RECT writeArea = { 0, 0, 0, 0 }; int i, j; CHAR_INFO line[MAX_EDIT_LINE]; WORD attrib; GetConsoleScreenBufferInfo(qconsole_hout, &binfo); // if we're in the middle of printf, don't bother writing the buffer if (binfo.dwCursorPosition.X != 0) { return; } writeArea.Left = 0; writeArea.Top = binfo.dwCursorPosition.Y; writeArea.Bottom = binfo.dwCursorPosition.Y; writeArea.Right = MAX_EDIT_LINE; // set color to white attrib = CON_ColorCharToAttrib(COLOR_WHITE); // build a space-padded CHAR_INFO array for (i = j = 0; j < MAX_EDIT_LINE; j++) { if (Q_IsColorString(qconsole_line + i)) { attrib = CON_ColorCharToAttrib(*(qconsole_line + i + 1)); i += 2; continue; } else if (qconsole_line[i] == Q_COLOR_ESCAPE) { i += 1; } if (i < qconsole_linelen) { line[j].Char.AsciiChar = qconsole_line[i]; ++i; } else { line[j].Char.AsciiChar = ' '; } line[j].Attributes = attrib; } if (qconsole_linelen > binfo.srWindow.Right) { WriteConsoleOutput(qconsole_hout, line + (qconsole_linelen - binfo.srWindow.Right), writeSize, writePos, &writeArea); } else { WriteConsoleOutput(qconsole_hout, line, writeSize, writePos, &writeArea); } }