added auto-completion to the Windows dedicated server

fixed Linux dedicated servers inserting a leading backslash when running auto-completion
fixed tty handling of the leading "]"
This commit is contained in:
myT 2017-05-18 23:23:50 +02:00
parent 9d18b2dfe5
commit 85d6762647
6 changed files with 39 additions and 15 deletions

View File

@ -55,6 +55,8 @@ chg: remove the byzantine r_mode usage added in 1.47
Windows: Windows:
add: auto-completion in the dedicated server console window
add: new bindable key: BACKSLASH (the key to the right of the left shift button) add: new bindable key: BACKSLASH (the key to the right of the left shift button)
fix: the crash handler will reset the system timer resolution fix: the crash handler will reset the system timer resolution
@ -68,6 +70,10 @@ chg: reduced raw mouse input latency and added cl_drawMouseLag
Linux: Linux:
fix: tty handling of the leading "]" character
fix: dedicated servers no longer insert a leading backslash when running auto-completion
fix: the crash handler will reset tty input mode correctly fix: the crash handler will reset tty input mode correctly
chg: tty input behavior matches in-game behavior when cgame is running and fixed the truncated tty input chg: tty input behavior matches in-game behavior when cgame is running and fixed the truncated tty input

View File

@ -494,7 +494,7 @@ static void Console_Key( int key )
// command completion // command completion
if (key == K_TAB) { if (key == K_TAB) {
Field_AutoComplete(&g_consoleField); Field_AutoComplete( &g_consoleField, qtrue );
return; return;
} }

View File

@ -2804,20 +2804,14 @@ void Field_AutoCompleteFrom( int startArg, int compArg, qbool searchCmds, qbool
} }
// returns qtrue if there already was a leading slash static void Field_AddLeadingSlash( field_t *field )
static qbool Field_EnsureLeadingSlash( field_t *field )
{ {
if ( String_HasLeadingSlash( field->buffer ) )
return qtrue;
const size_t length = strlen( field->buffer ); const size_t length = strlen( field->buffer );
if ( length + 1 < sizeof( field->buffer ) ) { if ( length + 1 < sizeof( field->buffer ) ) {
memmove( field->buffer + 1, field->buffer, length + 1 ); memmove( field->buffer + 1, field->buffer, length + 1 );
*field->buffer = '\\'; *field->buffer = '\\';
field->cursor++; field->cursor++;
} }
return qfalse;
} }
@ -2855,10 +2849,12 @@ static qbool Field_AutoCompleteNoLeadingSlash( field_t *field )
} }
void Field_AutoComplete( field_t *field ) void Field_AutoComplete( field_t *field, qbool insertBackslash )
{ {
const qbool ranComp = Field_AutoCompleteNoLeadingSlash( field ); const qbool ranComp = Field_AutoCompleteNoLeadingSlash( field );
const qbool hadSlash = Field_EnsureLeadingSlash( field ); const qbool hadSlash = String_HasLeadingSlash( field->buffer );
if ( !hadSlash && insertBackslash )
Field_AddLeadingSlash( field );
if ( ranComp ) if ( ranComp )
return; return;

View File

@ -657,7 +657,7 @@ typedef struct {
} field_t; } field_t;
void Field_Clear( field_t *edit ); void Field_Clear( field_t *edit );
void Field_AutoComplete( field_t *edit ); // should only be called by Console_Key void Field_AutoComplete( field_t *edit, qbool insertBackslash ); // should only be called by Console_Key
// these are the functions you can use from your own command argument auto-completion callbacks // these are the functions you can use from your own command argument auto-completion callbacks
void Field_AutoCompleteFrom( int startArg, int compArg, qbool searchCmds, qbool searchVars ); void Field_AutoCompleteFrom( int startArg, int compArg, qbool searchCmds, qbool searchVars );

View File

@ -135,6 +135,7 @@ static void tty_Hide()
tty_Back(); tty_Back();
} }
} }
tty_Back(); // delete the leading "]"
ttycon_hide++; ttycon_hide++;
} }
@ -148,6 +149,7 @@ static void tty_Show()
ttycon_hide--; ttycon_hide--;
if (ttycon_hide == 0) if (ttycon_hide == 0)
{ {
write(STDOUT_FILENO, "]", 1);
if (tty_con.cursor) if (tty_con.cursor)
{ {
for (i=0; i<tty_con.cursor; i++) for (i=0; i<tty_con.cursor; i++)
@ -341,7 +343,11 @@ const char* Sys_ConsoleInput()
if (key == '\t') if (key == '\t')
{ {
tty_Hide(); tty_Hide();
Field_AutoComplete( &tty_con ); #ifdef DEDICATED
Field_AutoComplete( &tty_con, qfalse );
#else
Field_AutoComplete( &tty_con, qtrue );
#endif
tty_Show(); tty_Show();
return NULL; return NULL;
} }
@ -442,6 +448,7 @@ void Sys_ConsoleInputShutdown()
{ {
if (ttycon_on) if (ttycon_on)
{ {
tty_Back(); // delete the leading "]"
tcsetattr (0, TCSADRAIN, &tty_tc); tcsetattr (0, TCSADRAIN, &tty_tc);
ttycon_on = qfalse; ttycon_on = qfalse;
} }

View File

@ -73,6 +73,7 @@ typedef struct
WNDPROC SysInputLineWndProc; WNDPROC SysInputLineWndProc;
field_t inputField;
} WinConData; } WinConData;
static WinConData s_wcd; static WinConData s_wcd;
@ -273,15 +274,29 @@ LONG WINAPI InputLineWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
break; break;
case WM_CHAR: case WM_CHAR:
if ( wParam == 13 ) if ( wParam == VK_RETURN )
{ {
GetWindowText( s_wcd.hwndInputLine, inputBuffer, sizeof( inputBuffer ) ); GetWindowText( s_wcd.hwndInputLine, inputBuffer, sizeof( inputBuffer ) );
strncat( s_wcd.consoleText, inputBuffer, sizeof( s_wcd.consoleText ) - strlen( s_wcd.consoleText ) - 5 ); strncat( s_wcd.consoleText, inputBuffer, sizeof( s_wcd.consoleText ) - strlen( s_wcd.consoleText ) - 5 );
strcat( s_wcd.consoleText, "\n" ); Q_strcat( s_wcd.consoleText, sizeof(s_wcd.consoleText), "\n" );
SetWindowText( s_wcd.hwndInputLine, "" ); SetWindowText( s_wcd.hwndInputLine, "" );
Sys_Print( va( "]%s\n", inputBuffer ) ); Sys_Print( va( "]%s\n", inputBuffer ) );
return 0;
}
if ( wParam == VK_TAB )
{
GetWindowText( s_wcd.hwndInputLine, s_wcd.inputField.buffer, sizeof( s_wcd.inputField.buffer ) );
SendMessage( s_wcd.hwndInputLine, EM_GETSEL, (WPARAM)&s_wcd.inputField.cursor, (LPARAM)NULL );
s_wcd.inputField.cursor = max( s_wcd.inputField.cursor, 0 );
s_wcd.inputField.scroll = 0;
s_wcd.inputField.widthInChars = 0;
Field_AutoComplete( &s_wcd.inputField, qfalse );
SetWindowText( s_wcd.hwndInputLine, s_wcd.inputField.buffer );
SendMessage( s_wcd.hwndInputLine, EM_SETSEL, (WPARAM)s_wcd.inputField.cursor, (LPARAM)s_wcd.inputField.cursor );
return 0; return 0;
} }
} }