diff options
author | Andrey Nazarov <skuller@skuller.net> | 2008-09-25 13:13:05 +0000 |
---|---|---|
committer | Andrey Nazarov <skuller@skuller.net> | 2008-09-25 13:13:05 +0000 |
commit | 95f993680be144ec40fa7f08002faf27a2e229a7 (patch) | |
tree | d1bf8e3174ffbe3e6bb332682b70c694b898da67 | |
parent | ea8394f51c74208866a891def93c55bd6cd3529e (diff) |
Strip trailing whitespace as gi.args() expects.
Properly set maxChars value for input fields on Unix.
-rw-r--r-- | source/cl_console.c | 4 | ||||
-rw-r--r-- | source/cmd.c | 9 | ||||
-rw-r--r-- | source/files.c | 1 | ||||
-rw-r--r-- | source/prompt.c | 43 | ||||
-rw-r--r-- | source/q_field.c | 267 | ||||
-rw-r--r-- | source/q_field.h | 23 | ||||
-rw-r--r-- | source/sv_user.c | 7 | ||||
-rw-r--r-- | source/sys_unix.c | 35 | ||||
-rw-r--r-- | source/sys_win.c | 46 | ||||
-rw-r--r-- | source/ui_menu.c | 3 | ||||
-rw-r--r-- | source/ui_playerconfig.c | 3 |
11 files changed, 251 insertions, 190 deletions
diff --git a/source/cl_console.c b/source/cl_console.c index 61d9d3e..af89fc5 100644 --- a/source/cl_console.c +++ b/source/cl_console.c @@ -404,8 +404,8 @@ void Con_Init( void ) { con_scroll = Cvar_Get( "con_scroll", "0", CVAR_ARCHIVE ); con_history = Cvar_Get( "con_history", "0", 0 ); - IF_Init( &con.prompt.inputLine, 1, MAX_FIELD_TEXT, NULL ); - IF_Init( &con.chatPrompt.inputLine, 1, MAX_FIELD_TEXT, NULL ); + IF_Init( &con.prompt.inputLine, 0, MAX_FIELD_TEXT - 1 ); + IF_Init( &con.chatPrompt.inputLine, 0, MAX_FIELD_TEXT - 1 ); con.prompt.printf = Con_Printf; diff --git a/source/cmd.c b/source/cmd.c index 528a3cf..0d57654 100644 --- a/source/cmd.c +++ b/source/cmd.c @@ -1036,6 +1036,15 @@ void Cmd_TokenizeString( const char *text, qboolean macroExpand ) { return; } +// strip off any trailing whitespace + while( cmd_string_len ) { + if( cmd_string[ cmd_string_len - 1 ] > ' ' ) { + break; + } + cmd_string[ cmd_string_len - 1 ] = 0; + cmd_string_len--; + } + dest = cmd_data; start = data = cmd_string; while( cmd_argc < MAX_STRING_TOKENS ) { diff --git a/source/files.c b/source/files.c index 8eee3fa..9bf7193 100644 --- a/source/files.c +++ b/source/files.c @@ -2414,7 +2414,6 @@ void FS_Shutdown( qboolean total ) { Cmd_RemoveCommand( "path" ); Cmd_RemoveCommand( "fdir" ); Cmd_RemoveCommand( "dir" ); - Cmd_RemoveCommand( "copyfile" ); Cmd_RemoveCommand( "fs_stats" ); Cmd_RemoveCommand( "link" ); Cmd_RemoveCommand( "unlink" ); diff --git a/source/prompt.c b/source/prompt.c index 6dfbe2d..49f5e0a 100644 --- a/source/prompt.c +++ b/source/prompt.c @@ -162,7 +162,7 @@ void Prompt_CompleteCommand( commandPrompt_t *prompt, qboolean backslash ) { int numCommands = 0, numCvars = 0, numAliases = 0; text = inputLine->text; - size = sizeof( inputLine->text ); + size = inputLine->maxChars + 1; pos = inputLine->cursorPos; // prepend backslash if missing @@ -227,9 +227,9 @@ void Prompt_CompleteCommand( commandPrompt_t *prompt, qboolean backslash ) { } if( !ctx.count ) { - inputLine->cursorPos = strlen( inputLine->text ); + pos = strlen( inputLine->text ); prompt->tooMany = qfalse; - return; // nothing found + goto finish2; // nothing found } pos = Cmd_ArgOffset( currentArg ); @@ -240,25 +240,20 @@ void Prompt_CompleteCommand( commandPrompt_t *prompt, qboolean backslash ) { // we have finished completion! s = Cmd_RawArgsFrom( currentArg + 1 ); if( COM_HasSpaces( matches[0] ) ) { - len = Q_concat( text, size, "\"", matches[0], "\" ", s, NULL ); + pos += Q_concat( text, size, "\"", matches[0], "\" ", s, NULL ); } else { - len = Q_concat( text, size, matches[0], " ", s, NULL ); + pos += Q_concat( text, size, matches[0], " ", s, NULL ); } - if( len >= size ) { - len = size - 1; - } - pos += len; - inputLine->cursorPos = pos + 1; + pos++; prompt->tooMany = qfalse; - goto finish; + goto finish1; } if( ctx.count > com_completion_treshold->integer && !prompt->tooMany ) { - prompt->printf( "Press TAB again to display all %d possibilities.\n", - ctx.count ); - inputLine->cursorPos = strlen( inputLine->text ); + prompt->printf( "Press TAB again to display all %d possibilities.\n", ctx.count ); + pos = strlen( inputLine->text ); prompt->tooMany = qtrue; - goto finish; + goto finish1; } prompt->tooMany = qfalse; @@ -293,16 +288,13 @@ void Prompt_CompleteCommand( commandPrompt_t *prompt, qboolean backslash ) { pos += len; size -= len; + // copy trailing arguments if( currentArg + 1 < argc ) { s = Cmd_RawArgsFrom( currentArg + 1 ); - len = Q_concat( text + len, size, " ", s, NULL ); - if( len >= size ) { - len = size - 1; - } - pos += len; + pos += Q_concat( text + len, size, " ", s, NULL ); } - inputLine->cursorPos = pos + 1; + pos++; prompt->printf( "]\\%s\n", Cmd_ArgsFrom( 0 ) ); if( argnum ) { @@ -328,11 +320,18 @@ void Prompt_CompleteCommand( commandPrompt_t *prompt, qboolean backslash ) { break; } -finish: +finish1: // free matches for( i = 0; i < ctx.count; i++ ) { Z_Free( matches[i] ); } + +finish2: + // move cursor + if( pos >= inputLine->maxChars ) { + pos = inputLine->maxChars - 1; + } + inputLine->cursorPos = pos; } void Prompt_CompleteHistory( commandPrompt_t *prompt, qboolean forward ) { diff --git a/source/q_field.c b/source/q_field.c index 1846a63..bd92caf 100644 --- a/source/q_field.c +++ b/source/q_field.c @@ -33,15 +33,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. IF_Init ================ */ -void IF_Init( inputField_t *field, size_t visibleChars, size_t maxChars, const char *text ) { - memset( field, 0, sizeof( *field ) ); +void IF_Init( inputField_t *field, size_t visibleChars, size_t maxChars ) { + memset( field, 0, sizeof( *field ) ); - field->maxChars = clamp( maxChars, 1, sizeof( field->text ) ); - field->visibleChars = clamp( visibleChars, 1, maxChars ); - if( text ) { - size_t len = Q_strlcpy( field->text, text, maxChars ); - field->cursorPos = len >= maxChars ? maxChars - 1 : len; + if( maxChars > sizeof( field->text ) - 1 ) { + maxChars = sizeof( field->text ) - 1; } + if( visibleChars > maxChars ) { + visibleChars = maxChars; + } + + field->maxChars = maxChars; + field->visibleChars = visibleChars; } /* @@ -50,8 +53,8 @@ IF_Clear ================ */ void IF_Clear( inputField_t *field ) { - memset( field->text, 0, sizeof( field->text ) ); - field->cursorPos = 0; + memset( field->text, 0, sizeof( field->text ) ); + field->cursorPos = 0; } /* @@ -60,9 +63,12 @@ IF_Replace ================ */ void IF_Replace( inputField_t *field, const char *text ) { - if( text ) { - size_t len = Q_strlcpy( field->text, text, field->maxChars ); - field->cursorPos = len >= field->maxChars ? field->maxChars - 1 : len; + if( field->maxChars && text ) { + size_t len = Q_strlcpy( field->text, text, field->maxChars + 1 ); + field->cursorPos = len >= field->maxChars ? field->maxChars - 1 : len; + } else { + field->text[0] = 0; + field->cursorPos = 0; } } @@ -74,44 +80,51 @@ IF_KeyEvent ================ */ qboolean IF_KeyEvent( inputField_t *field, int key ) { - if( key == K_DEL ) { - if( field->text[field->cursorPos] ) { - memmove( field->text + field->cursorPos, + if( !field->maxChars ) { + return qfalse; + } + if( field->cursorPos >= field->maxChars ) { + Com_Error( ERR_FATAL, "%s: bad cursorPos", __func__ ); + } + + if( key == K_DEL ) { + if( field->text[field->cursorPos] ) { + memmove( field->text + field->cursorPos, field->text + field->cursorPos + 1, sizeof( field->text ) - field->cursorPos ); - } - return qtrue; - } - - if( key == K_BACKSPACE || ( key == 'h' && Key_IsDown( K_CTRL ) ) ) { - if( field->cursorPos > 0 ) { - memmove( field->text + field->cursorPos - 1, + } + return qtrue; + } + + if( key == K_BACKSPACE || ( key == 'h' && Key_IsDown( K_CTRL ) ) ) { + if( field->cursorPos > 0 ) { + memmove( field->text + field->cursorPos - 1, field->text + field->cursorPos, sizeof( field->text ) - field->cursorPos ); - field->cursorPos--; - } - return qtrue; - } + field->cursorPos--; + } + return qtrue; + } if( key == 'w' && Key_IsDown( K_CTRL ) ) { size_t oldpos = field->cursorPos; // kill trailing whitespace - while( field->cursorPos > 0 && field->text[field->cursorPos] <= 32 ) { - field->cursorPos--; + while( field->cursorPos > 0 && field->text[field->cursorPos] <= 32 ) { + field->cursorPos--; } // kill this word - while( field->cursorPos > 0 && field->text[ field->cursorPos - 1 ] > 32 ) { - field->cursorPos--; + while( field->cursorPos > 0 && field->text[ field->cursorPos - 1 ] > 32 ) { + field->cursorPos--; } - memmove( field->text + field->cursorPos, field->text + oldpos, + memmove( field->text + field->cursorPos, field->text + oldpos, sizeof( field->text ) - oldpos ); return qtrue; } if( key == 'u' && Key_IsDown( K_CTRL ) ) { - memmove( field->text, field->text + field->cursorPos, + memmove( field->text, field->text + field->cursorPos, sizeof( field->text ) - field->cursorPos ); field->cursorPos = 0; return qtrue; @@ -126,60 +139,60 @@ qboolean IF_KeyEvent( inputField_t *field, int key ) { VID_SetClipboardData( field->text ); return qtrue; } - - if( key == K_LEFTARROW || ( key == 'b' && Key_IsDown( K_CTRL ) ) ) { - if( field->cursorPos > 0 ) { - field->cursorPos--; - } - return qtrue; - } - - if( key == K_RIGHTARROW || ( key == 'f' && Key_IsDown( K_CTRL ) ) ) { - if( field->text[field->cursorPos] ) { - field->cursorPos++; - } - return qtrue; - } - - if( key == 'b' && Key_IsDown( K_ALT ) ) { - if( field->cursorPos > 0 && field->text[field->cursorPos - 1] <= 32 ) { - field->cursorPos--; - } - while( field->cursorPos > 0 && field->text[field->cursorPos] <= 32 ) { - field->cursorPos--; - } - while( field->cursorPos > 0 && field->text[field->cursorPos - 1] > 32 ) { - field->cursorPos--; - } - return qtrue; - } - - if( key == 'f' && Key_IsDown( K_ALT ) ) { - while( field->text[field->cursorPos] && field->text[field->cursorPos] <= 32 ) { - field->cursorPos++; - } - while( field->text[field->cursorPos] > 32 ) { - field->cursorPos++; - } - return qtrue; - } - - if( key == K_HOME || ( key == 'a' && Key_IsDown( K_CTRL ) ) ) { - field->cursorPos = 0; - return qtrue; - } - - if( key == K_END || ( key == 'e' && Key_IsDown( K_CTRL ) ) ) { - field->cursorPos = strlen( field->text ); - return qtrue; - } - - if( key == K_INS ) { - Key_SetOverstrikeMode( Key_GetOverstrikeMode() ^ 1 ); - return qtrue; - } - - return qfalse; + + if( key == K_LEFTARROW || ( key == 'b' && Key_IsDown( K_CTRL ) ) ) { + if( field->cursorPos > 0 ) { + field->cursorPos--; + } + return qtrue; + } + + if( key == K_RIGHTARROW || ( key == 'f' && Key_IsDown( K_CTRL ) ) ) { + if( field->text[field->cursorPos] ) { + field->cursorPos++; + } + return qtrue; + } + + if( key == 'b' && Key_IsDown( K_ALT ) ) { + if( field->cursorPos > 0 && field->text[field->cursorPos - 1] <= 32 ) { + field->cursorPos--; + } + while( field->cursorPos > 0 && field->text[field->cursorPos] <= 32 ) { + field->cursorPos--; + } + while( field->cursorPos > 0 && field->text[field->cursorPos - 1] > 32 ) { + field->cursorPos--; + } + return qtrue; + } + + if( key == 'f' && Key_IsDown( K_ALT ) ) { + while( field->text[field->cursorPos] && field->text[field->cursorPos] <= 32 ) { + field->cursorPos++; + } + while( field->text[field->cursorPos] > 32 ) { + field->cursorPos++; + } + return qtrue; + } + + if( key == K_HOME || ( key == 'a' && Key_IsDown( K_CTRL ) ) ) { + field->cursorPos = 0; + return qtrue; + } + + if( key == K_END || ( key == 'e' && Key_IsDown( K_CTRL ) ) ) { + field->cursorPos = strlen( field->text ); + return qtrue; + } + + if( key == K_INS ) { + Key_SetOverstrikeMode( Key_GetOverstrikeMode() ^ 1 ); + return qtrue; + } + + return qfalse; } /* @@ -188,30 +201,36 @@ IF_CharEvent ================ */ qboolean IF_CharEvent( inputField_t *field, int key ) { - if( key < 32 || key > 127 ) { - return qfalse; // non printable - } - - if( field->cursorPos >= field->maxChars - 1 ) { - // buffer limit was reached, just replace the last character - field->text[field->cursorPos] = key; - return qtrue; - } - - if( Key_GetOverstrikeMode() ) { - // replace the character at cursor and advance - field->text[field->cursorPos] = key; - field->cursorPos++; - return qtrue; - } - - // insert new character at cursor position - memmove( field->text + field->cursorPos + 1, field->text + field->cursorPos, + if( !field->maxChars ) { + return qfalse; + } + if( key < 32 || key > 127 ) { + return qfalse; // non printable + } + + if( field->cursorPos >= field->maxChars ) { + Com_Error( ERR_FATAL, "%s: bad cursorPos", __func__ ); + } + + if( field->cursorPos == field->maxChars - 1 ) { + // buffer limit was reached, just replace the last character + field->text[field->cursorPos] = key; + return qtrue; + } + + if( Key_GetOverstrikeMode() ) { + // replace the character at cursor and advance + field->text[field->cursorPos++] = key; + return qtrue; + } + + // insert new character at cursor position + memmove( field->text + field->cursorPos + 1, + field->text + field->cursorPos, sizeof( field->text ) - field->cursorPos - 1 ); - field->text[field->cursorPos] = key; - field->cursorPos++; + field->text[field->cursorPos++] = key; - return qtrue; + return qtrue; } /* @@ -223,25 +242,29 @@ Returns x offset of the rightmost character drawn. ================ */ int IF_Draw( inputField_t *field, int x, int y, int flags, qhandle_t font ) { - char *text = field->text; - size_t cursorPos = field->cursorPos; + char *text = field->text; + size_t cursorPos = field->cursorPos; size_t offset = 0; - int ret; + int ret; - if( cursorPos >= sizeof( field->text ) ) { - Com_Error( ERR_FATAL, "IF_Draw: bad field->cursorPos" ); - } + if( !field->visibleChars ) { + return 0; + } - // scroll horizontally - if( cursorPos > field->visibleChars - 1 ) { - cursorPos = field->visibleChars - 1; - offset = field->cursorPos - cursorPos; - } + if( cursorPos >= field->maxChars ) { + Com_Error( ERR_FATAL, "%s: bad cursorPos", __func__ ); + } + + // scroll horizontally + if( cursorPos >= field->visibleChars ) { + cursorPos = field->visibleChars - 1; + offset = field->cursorPos - cursorPos; + } - // draw text - ret = R_DrawString( x, y, flags, field->visibleChars, text + offset, font ); + // draw text + ret = R_DrawString( x, y, flags, field->visibleChars, text + offset, font ); - if( flags & UI_DRAWCURSOR ) { + if( flags & UI_DRAWCURSOR ) { // draw blinking cursor if( ( com_localTime >> 8 ) & 1 ) { int c = Key_GetOverstrikeMode() ? 11 : '_'; diff --git a/source/q_field.h b/source/q_field.h index eeca72a..7c0a6b8 100644 --- a/source/q_field.h +++ b/source/q_field.h @@ -27,20 +27,19 @@ LINE EDITING =============================================================================== */ -#define MAX_FIELD_TEXT 256 +#define MAX_FIELD_TEXT 256 typedef struct inputField_s { - char text[MAX_FIELD_TEXT]; - size_t maxChars; - size_t visibleChars; - size_t cursorPos; + char text[MAX_FIELD_TEXT]; + size_t maxChars; + size_t visibleChars; + size_t cursorPos; } inputField_t; -qboolean IF_KeyEvent( inputField_t *field, int key ); -qboolean IF_CharEvent( inputField_t *field, int key ); -void IF_Init( inputField_t *field, size_t visibleChars, size_t maxChars, const char *text ); -void IF_Clear( inputField_t *field ); -void IF_Replace( inputField_t *field, const char *text ); -int IF_Draw( inputField_t *field, int x, int y, int flags, - qhandle_t hFont ); +qboolean IF_KeyEvent( inputField_t *field, int key ); +qboolean IF_CharEvent( inputField_t *field, int key ); +void IF_Init( inputField_t *field, size_t visibleChars, size_t maxChars ); +void IF_Clear( inputField_t *field ); +void IF_Replace( inputField_t *field, const char *text ); +int IF_Draw( inputField_t *field, int x, int y, int flags, qhandle_t font ); diff --git a/source/sv_user.c b/source/sv_user.c index 0ee0917..52a3b8b 100644 --- a/source/sv_user.c +++ b/source/sv_user.c @@ -1154,8 +1154,11 @@ void SV_ExecuteClientMessage( client_t *client ) { SV_DropClient( client, "oversize stringcmd" ); break; } - - Com_DPrintf( "ClientCommand( %s ): %s\n", client->name, buffer ); + + if( developer->integer ) { + Com_Printf( S_COLOR_BLUE "ClientCommand( %s ): %s\n", + client->name, Q_FormatString( buffer ) ); + } // malicious users may try using too many string commands if( stringCmdCount == MAX_PACKET_STRINGCMDS ) { diff --git a/source/sys_unix.c b/source/sys_unix.c index 7c1a606..316cee0 100644 --- a/source/sys_unix.c +++ b/source/sys_unix.c @@ -126,6 +126,7 @@ static void Sys_InitTTY( void ) { #ifdef TIOCGWINSZ struct winsize ws; #endif + int width; tcgetattr( 0, &tty_orig ); tty = tty_orig; @@ -133,15 +134,27 @@ static void Sys_InitTTY( void ) { tty.c_cc[VMIN] = 1; tty.c_cc[VTIME] = 0; tcsetattr( 0, TCSADRAIN, &tty ); - tty_prompt.widthInChars = 80; + + // determine terminal width + width = 80; #ifdef TIOCGWINSZ if( ioctl( 0, TIOCGWINSZ, &ws ) == 0 ) { - tty_prompt.widthInChars = ws.ws_col; + if( ws.ws_col ) { + width = ws.ws_col; + } } #endif + tty_prompt.widthInChars = width; tty_prompt.printf = Sys_Printf; tty_enabled = qtrue; + // figure out input line width + width--; + if( width > MAX_FIELD_TEXT - 1 ) { + width = MAX_FIELD_TEXT - 1; + } + IF_Init( &tty_prompt.inputLine, width, width ); + Sys_ConsoleWrite( " ", 1 ); } @@ -284,11 +297,15 @@ static void Sys_ParseInput( const char *text ) { } if( key >= 32 ) { - if( f->cursorPos < sizeof( f->text ) - 1 ) { - char c = key; - Sys_ConsoleWrite( &c, 1 ); - f->text[f->cursorPos] = c; - f->text[++f->cursorPos] = 0; + if( f->cursorPos == f->maxChars - 1 ) { + Sys_ConsoleWrite( va( "\b \b%c", key ), 4 ); + f->text[f->cursorPos+0] = key; + f->text[f->cursorPos+1] = 0; + } else { + Sys_ConsoleWrite( va( "%c", key ), 1 ); + f->text[f->cursorPos+0] = key; + f->text[f->cursorPos+1] = 0; + f->cursorPos++; } continue; } @@ -310,10 +327,12 @@ static void Sys_ParseInput( const char *text ) { } if( key == '\t' ) { + //Con_Print(va("before=%d (%s)\n",tty_prompt.inputLine.cursorPos,tty_prompt.inputLine.text) ); Sys_HideInput(); Prompt_CompleteCommand( &tty_prompt, qfalse ); - f->cursorPos = strlen( f->text ); + f->cursorPos = strlen( f->text ); // FIXME Sys_ShowInput(); + //Con_Print(va("after=%d (%s)\n",tty_prompt.inputLine.cursorPos,tty_prompt.inputLine.text) ); continue; } diff --git a/source/sys_win.c b/source/sys_win.c index 79968bf..a96b913 100644 --- a/source/sys_win.c +++ b/source/sys_win.c @@ -190,8 +190,7 @@ void Sys_RunConsole( void ) { f = &sys_con.inputLine; while( 1 ) { if( !GetNumberOfConsoleInputEvents( hinput, &numevents ) ) { - Com_EPrintf( "Error %lu getting number of console events.\n" - "Console IO disabled.\n", GetLastError() ); + Com_EPrintf( "Error %lu getting number of console events.\n", GetLastError() ); gotConsole = qfalse; return; } @@ -203,8 +202,7 @@ void Sys_RunConsole( void ) { } if( !ReadConsoleInput( hinput, recs, numevents, &numread ) ) { - Com_EPrintf( "Error %lu reading console input.\n" - "Console IO disabled.\n", GetLastError() ); + Com_EPrintf( "Error %lu reading console input.\n", GetLastError() ); gotConsole = qfalse; return; } @@ -250,15 +248,13 @@ void Sys_RunConsole( void ) { break; case VK_BACK: if( f->cursorPos ) { - f->cursorPos--; - f->text[f->cursorPos] = 0; + f->text[--f->cursorPos] = 0; WriteFile( houtput, "\b \b", 3, &dummy, NULL ); } break; case VK_TAB: Sys_HideInput(); Prompt_CompleteCommand( &sys_con, qfalse ); - f->cursorPos = ( int )strlen( f->text ); Sys_ShowInput(); break; default: @@ -266,11 +262,10 @@ void Sys_RunConsole( void ) { if( ch < 32 ) { break; } - if( f->cursorPos < sizeof( f->text ) - 1 ) { + if( f->cursorPos < f->maxChars - 1 ) { WriteFile( houtput, &ch, 1, &dummy, NULL ); f->text[f->cursorPos] = ch; - f->text[f->cursorPos+1] = 0; - f->cursorPos++; + f->text[++f->cursorPos] = 0; } break; } @@ -281,7 +276,7 @@ void Sys_RunConsole( void ) { #define FOREGROUND_BLACK 0 #define FOREGROUND_WHITE (FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED) -static WORD textColors[8] = { +static const WORD textColors[8] = { FOREGROUND_BLACK, FOREGROUND_RED, FOREGROUND_GREEN, @@ -381,18 +376,18 @@ static BOOL WINAPI Sys_ConsoleCtrlHandler( DWORD dwCtrlType ) { if( errorEntered ) { exit( 1 ); } - /* 32 bit writes are guranteed to be atomic */ + // 32 bit writes are guranteed to be atomic shouldExit = qtrue; return TRUE; } static void Sys_ConsoleInit( void ) { DWORD mode; + int width; #if USE_CLIENT if( !AllocConsole() ) { - Com_EPrintf( "Couldn't create system console.\n" - "Console IO disabled.\n" ); + Com_EPrintf( "Couldn't create system console.\n" ); return; } #else @@ -404,19 +399,32 @@ static void Sys_ConsoleInit( void ) { hinput = GetStdHandle( STD_INPUT_HANDLE ); houtput = GetStdHandle( STD_OUTPUT_HANDLE ); if( !GetConsoleScreenBufferInfo( houtput, &sbinfo ) ) { - Com_EPrintf( "Couldn't get console buffer info.\n" - "Console IO disabled.\n" ); + Com_EPrintf( "Couldn't get console buffer info.\n" ); return; } + // determine terminal width + width = sbinfo.dwSize.X; + if( !width ) { + Com_EPrintf( "Invalid console buffer width.\n" ); + return; + } + sys_con.widthInChars = width; + sys_con.printf = Sys_Printf; + gotConsole = qtrue; + SetConsoleTitle( APPLICATION " console" ); SetConsoleCtrlHandler( Sys_ConsoleCtrlHandler, TRUE ); GetConsoleMode( hinput, &mode ); mode |= ENABLE_WINDOW_INPUT; SetConsoleMode( hinput, mode ); - sys_con.widthInChars = sbinfo.dwSize.X; - sys_con.printf = Sys_Printf; - gotConsole = qtrue; + + // figure out input line width + width--; + if( width > MAX_FIELD_TEXT - 1 ) { + width = MAX_FIELD_TEXT - 1; + } + IF_Init( &sys_con.inputLine, width, width ); Com_DPrintf( "System console initialized (%d cols, %d rows).\n", sbinfo.dwSize.X, sbinfo.dwSize.Y ); diff --git a/source/ui_menu.c b/source/ui_menu.c index c8ad285..7ff4a42 100644 --- a/source/ui_menu.c +++ b/source/ui_menu.c @@ -274,7 +274,8 @@ FIELD CONTROL */ static void Field_Push( menuField_t *f ) { - IF_Init( &f->field, f->width, MAX_FIELD_TEXT, f->cvar->string ); + IF_Init( &f->field, f->width, MAX_FIELD_TEXT - 1 ); + IF_Replace( &f->field, f->cvar->string ); } static void Field_Pop( menuField_t *f ) { diff --git a/source/ui_playerconfig.c b/source/ui_playerconfig.c index 4c5978e..6070a3d 100644 --- a/source/ui_playerconfig.c +++ b/source/ui_playerconfig.c @@ -216,7 +216,8 @@ static qboolean Push( menuFrameWork_t *self ) { } } - IF_Init( &m_player.name.field, 16, 16, Cvar_VariableString( "name" ) ); + IF_Init( &m_player.name.field, 16, 16 ); + IF_Replace( &m_player.name.field, Cvar_VariableString( "name" ) ); m_player.model.curvalue = currentdirectoryindex; m_player.model.itemnames = m_player.pmnames; |