- 论坛徽章:
- 0
|
大概像这样,自己再看看
void ConsoleOutput( CONSOLEFORMAT fmt, const char* sz, ... )
{
int iCount;
va_list args;
strcpy(szConsoleOutputBuf, "");
/*
** If the Output is going to the "INPUT" type....we don't parse for special
** characters like "%", they should have been handled by the caller
*/
if ( fmt == INPUT )
{
strcpy( szConsoleOutputBuf, sz );
iCount = 1;
}
else
{
va_start( args, sz );
iCount = vsprintf( szConsoleOutputBuf, sz, args );
va_end( args );
}
if ( iCount < 0 )
{
return;
}
#if 0
// This is a reminder....They can be ORred together
FOREGROUND_BLUE
FOREGROUND_GREEN
FOREGROUND_RED
FOREGROUND_INTENSITY
BACKGROUND_BLUE
BACKGROUND_GREEN
BACKGROUND_RED
BACKGROUND_INTENSITY
#endif
#ifdef WIN32
#define PROMPTCOLOR (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED)
#define INPUTCOLOR (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY)
#define HELPCOLOR (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY)
#define OUTPUTCOLOR (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED)
#define TITLECOLOR (FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY)
#define HISTORYCOLOR (FOREGROUND_GREEN | FOREGROUND_RED)
#define DEFAULTCOLOR (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED)
#define ERRORCOLOR (FOREGROUND_RED | FOREGROUND_INTENSITY)
#else // WIN32
// Foreground colors first
#define ANSI_FBLACK "\033[30m"
#define ANSI_FRED "\033[31m"
#define ANSI_FGREEN "\033[32m"
#define ANSI_FYELLOW "\033[33m"
#define ANSI_FBLUE "\033[34m"
#define ANSI_FMAGENTA "\033[35m"
#define ANSI_FCYAN "\033[36m"
#define ANSI_FWHITE "\033[37m"
#define ANSI_BBLACK "\033[40m"
#define ANSI_BRED "\033[41m"
#define ANSI_BGREEN "\033[42m"
#define ANSI_BYELLOW "\033[43m"
#define ANSI_BBLUE "\033[44m"
#define ANSI_BMAGENTA "\033[45m"
#define ANSI_BCYAN "\033[46m"
#define ANSI_BWHITE "\033[47m"
#define ANSI_CLEAR "\033[0m"
#define ANSI_BOLD "\033[1m"
#define ANSI_UNDER "\033[4m"
#define ANSI_BLINK "\033[5m"
#define ANSI_INVERT "\033[7m"
// Assume Linux - ANSI Color Sequences
#define PROMPTCOLOR (ANSI_FWHITE ANSI_BBLACK)
#define INPUTCOLOR (ANSI_FCYAN ANSI_BOLD ANSI_BBLACK)
#define HELPCOLOR (ANSI_FWHITE ANSI_BOLD ANSI_BBLACK)
#define OUTPUTCOLOR (ANSI_FWHITE ANSI_BBLACK)
#define TITLECOLOR (ANSI_FYELLOW ANSI_BOLD ANSI_BBLACK)
#define HISTORYCOLOR (ANSI_FYELLOW ANSI_BBLACK)
#define DEFAULTCOLOR (ANSI_CLEAR)
#define ERRORCOLOR (ANSI_FRED ANSI_BOLD ANSI_BBLACK)
#endif // WIN32
if ( fmt != LOGONLY )
{
#ifdef WIN32
WORD colorCode = DEFAULTCOLOR;
#else // WIN32
char* colorCode = DEFAULTCOLOR;
#endif // WIN32
switch ( fmt )
{
case PROMPT: colorCode = PROMPTCOLOR; break;
case INPUT: colorCode = INPUTCOLOR; break;
case HELP: colorCode = HELPCOLOR; break;
case OUTPUT: colorCode = OUTPUTCOLOR; break;
case TITLE: colorCode = TITLECOLOR; break;
case HISTORY: colorCode = HISTORYCOLOR; break;
case ERRORMSG: colorCode = ERRORCOLOR; break;
default: colorCode = DEFAULTCOLOR; break;
}
if ( gConsoleColorEnable )
{
#ifdef WIN32
SetConsoleTextAttribute( outputHandle, colorCode );
#else // WIN32
fputs( colorCode, stdout );
fflush( stdout );
#endif // WIN32
}
fputs( szConsoleOutputBuf, stdout );
fflush( stdout );
if ( gConsoleColorEnable )
{
#ifdef WIN32
SetConsoleTextAttribute( outputHandle, DEFAULTCOLOR );
#else // WIN32
colorCode = DEFAULTCOLOR;
fputs( colorCode, stdout );
fflush( stdout );
#endif // WIN32
}
if ( fhLogging != NULL )
{
fputs( szConsoleOutputBuf, fhLogging );
fflush( fhLogging );
}
}
else
{
if ( fhEngineLogging != NULL )
{
fputs( szConsoleOutputBuf, fhEngineLogging );
fflush( fhEngineLogging );
}
}
myprintf(szConsoleOutputBuf);
} |
|