static int CON_CursorPosFromScroll( void ) { // if we have wide char support, we have ncurses, and probably wcwidth too. int i, p = Field_ScrollToOffset( &input_field ), c = 0; for ( i = input_field.scroll; i < input_field.cursor; ++i ) { c += CON_wcwidth( input_field.buffer + p ); p += Q_UTF8Width( input_field.buffer + p ); } return c; }
void CL_ConsolePrint( char *txt ) { int y; int c, i, l; int color; qboolean skipnotify = qfalse; // NERVE - SMF int prev; // NERVE - SMF // NERVE - SMF - work around for text that shows up in console but not in notify if ( !Q_strncmp( txt, "[skipnotify]", 12 ) ) { skipnotify = qtrue; txt += 12; } // for some demos we don't want to ever show anything on the console if ( cl_noprint && cl_noprint->integer ) { return; } if ( !con.initialized ) { con.color[ 0 ] = con.color[ 1 ] = con.color[ 2 ] = con.color[ 3 ] = 1.0f; con.linewidth = -1; Con_CheckResize(); con.initialized = qtrue; } if ( !skipnotify && !( cls.keyCatchers & KEYCATCH_CONSOLE ) && strncmp( txt, "EXCL: ", 6 ) ) { // feed the text to cgame Cmd_SaveCmdContext(); Cmd_TokenizeString( txt ); CL_GameConsoleText(); Cmd_RestoreCmdContext(); } color = ColorIndex( CONSOLE_COLOR ); while ( ( c = *txt & 0xFF ) != 0 ) { if ( Q_IsColorString( txt ) ) { color = ( txt[ 1 ] == COLOR_NULL ) ? ColorIndex( CONSOLE_COLOR ) : ColorIndex( txt[ 1 ] ); txt += 2; continue; } // count word length for ( i = l = 0; l < con.linewidth; ++l ) { if ( txt[ i ] <= ' ' && txt[ i ] >= 0 ) { break; } if ( txt[ i ] == Q_COLOR_ESCAPE && txt[ i + 1 ] == Q_COLOR_ESCAPE ) { ++i; } i += Q_UTF8Width( txt + i ); } // word wrap if ( l != con.linewidth && ( con.x + l >= con.linewidth ) ) { Con_Linefeed( skipnotify ); } switch ( c ) { case '\n': Con_Linefeed( skipnotify ); break; case '\r': con.x = 0; break; case Q_COLOR_ESCAPE: if ( txt[ 1 ] == Q_COLOR_ESCAPE ) { ++txt; } default: // display character and advance y = con.current % con.totallines; // rain - sign extension caused the character to carry over // into the color info for high ascii chars; casting c to unsigned con.text[ y * con.linewidth + con.x ].ch = Q_UTF8CodePoint( txt ); con.text[ y * con.linewidth + con.x ].ink = color; ++con.x; if ( con.x >= con.linewidth ) { Con_Linefeed( skipnotify ); con.x = 0; } break; } txt += Q_UTF8Width( txt ); } // mark time for transparent overlay if ( con.current >= 0 ) { // NERVE - SMF if ( skipnotify ) { prev = con.current % NUM_CON_TIMES - 1; if ( prev < 0 ) { prev = NUM_CON_TIMES - 1; } con.times[ prev ] = 0; } else { // -NERVE - SMF con.times[ con.current % NUM_CON_TIMES ] = cls.realtime; } } }