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:
add: auto-completion in the dedicated server console window
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
@ -68,6 +70,10 @@ chg: reduced raw mouse input latency and added cl_drawMouseLag
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
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
if (key == K_TAB) {
Field_AutoComplete(&g_consoleField);
Field_AutoComplete( &g_consoleField, qtrue );
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 qbool Field_EnsureLeadingSlash( field_t *field )
static void Field_AddLeadingSlash( field_t *field )
{
if ( String_HasLeadingSlash( field->buffer ) )
return qtrue;
const size_t length = strlen( field->buffer );
if ( length + 1 < sizeof( field->buffer ) ) {
memmove( field->buffer + 1, field->buffer, length + 1 );
*field->buffer = '\\';
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 hadSlash = Field_EnsureLeadingSlash( field );
const qbool hadSlash = String_HasLeadingSlash( field->buffer );
if ( !hadSlash && insertBackslash )
Field_AddLeadingSlash( field );
if ( ranComp )
return;

View File

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

View File

@ -73,6 +73,7 @@ typedef struct
WNDPROC SysInputLineWndProc;
field_t inputField;
} WinConData;
static WinConData s_wcd;
@ -273,15 +274,29 @@ LONG WINAPI InputLineWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
break;
case WM_CHAR:
if ( wParam == 13 )
if ( wParam == VK_RETURN )
{
GetWindowText( s_wcd.hwndInputLine, inputBuffer, sizeof( inputBuffer ) );
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, "" );
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;
}
}