aboutsummaryrefslogtreecommitdiffstats
path: root/code/unix/unix_main.c
diff options
context:
space:
mode:
authortma <tma@edf5b092-35ff-0310-97b2-ce42778d08ea>2005-10-19 01:51:19 +0000
committertma <tma@edf5b092-35ff-0310-97b2-ce42778d08ea>2005-10-19 01:51:19 +0000
commitd1b40116d4c2cfb5c3e01c55449e9c953f425a39 (patch)
tree4aff10b69a43765840c6912a7fa588721058870f /code/unix/unix_main.c
parent35f3b338c5e2473c3be3c6ac78a431bd7670d0b5 (diff)
downloadioquake3-aero-d1b40116d4c2cfb5c3e01c55449e9c953f425a39.tar.gz
ioquake3-aero-d1b40116d4c2cfb5c3e01c55449e9c953f425a39.zip
* Silly little patch to convert Q3 style color codes to ANSI escape codes. Note
this doesn't work too well with baseq3 since it logs color strings with no color termination. git-svn-id: svn://svn.icculus.org/quake3/trunk@165 edf5b092-35ff-0310-97b2-ce42778d08ea
Diffstat (limited to 'code/unix/unix_main.c')
-rw-r--r--code/unix/unix_main.c87
1 files changed, 86 insertions, 1 deletions
diff --git a/code/unix/unix_main.c b/code/unix/unix_main.c
index 51a302a..95e4689 100644
--- a/code/unix/unix_main.c
+++ b/code/unix/unix_main.c
@@ -85,6 +85,9 @@ static struct termios tty_tc;
static field_t tty_con;
+static cvar_t *ttycon_ansicolor = NULL;
+static qboolean ttycon_color_on = qfalse;
+
// history
// NOTE TTimo this is a bit duplicate of the graphical console history
// but it's safer and faster to write our own here
@@ -519,6 +522,12 @@ void Sys_ConsoleInputInit( void )
tc.c_cc[VTIME] = 0;
tcsetattr (0, TCSADRAIN, &tc);
ttycon_on = qtrue;
+
+ ttycon_ansicolor = Cvar_Get( "ttycon_ansicolor", "0", CVAR_ARCHIVE );
+ if( ttycon_ansicolor && ttycon_ansicolor->value )
+ {
+ ttycon_color_on = qtrue;
+ }
} else
ttycon_on = qfalse;
}
@@ -1178,13 +1187,89 @@ char *Sys_GetClipboardData(void)
return NULL;
}
+static struct Q3ToAnsiColorTable_s
+{
+ char Q3color;
+ char *ANSIcolor;
+} tty_colorTable[ ] =
+{
+ { COLOR_BLACK, "30" },
+ { COLOR_RED, "31" },
+ { COLOR_GREEN, "32" },
+ { COLOR_YELLOW, "33" },
+ { COLOR_BLUE, "34" },
+ { COLOR_CYAN, "36" },
+ { COLOR_MAGENTA, "35" },
+ { COLOR_WHITE, "0" }
+};
+
+static int tty_colorTableSize =
+ sizeof( tty_colorTable ) / sizeof( tty_colorTable[ 0 ] );
+
+void Sys_ANSIColorify( const char *msg, char *buffer, int bufferSize )
+{
+ int msgLength, pos;
+ int i, j;
+ char *escapeCode;
+
+ if( !msg || !buffer )
+ return;
+
+ msgLength = strlen( msg );
+ pos = 0;
+ i = 0;
+ buffer[ 0 ] = '\0';
+
+ while( i < msgLength )
+ {
+ if( msg[ i ] == '\n' )
+ {
+ strncat( buffer, va( "%c[0m\n", 0x1B ), bufferSize );
+ i++;
+ }
+ else if( msg[ i ] == Q_COLOR_ESCAPE )
+ {
+ i++;
+
+ if( i < msgLength )
+ {
+ escapeCode = NULL;
+ for( j = 0; j < tty_colorTableSize; j++ )
+ {
+ if( msg[ i ] == tty_colorTable[ j ].Q3color )
+ {
+ escapeCode = tty_colorTable[ j ].ANSIcolor;
+ break;
+ }
+ }
+
+ if( escapeCode )
+ strncat( buffer, va( "%c[%sm", 0x1B, escapeCode ), bufferSize );
+
+ i++;
+ }
+ }
+ else
+ strncat( buffer, va( "%c", msg[ i++ ] ), bufferSize );
+ }
+}
+
void Sys_Print( const char *msg )
{
if (ttycon_on)
{
tty_Hide();
}
- fputs(msg, stderr);
+
+ if( ttycon_on && ttycon_color_on )
+ {
+ char ansiColorString[ MAXPRINTMSG ];
+ Sys_ANSIColorify( msg, ansiColorString, MAXPRINTMSG );
+ fputs( ansiColorString, stderr );
+ }
+ else
+ fputs(msg, stderr);
+
if (ttycon_on)
{
tty_Show();