mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2025-02-16 00:52:30 +00:00
console.c: Steven's patch making console command completion display a little
more like bash, showing the maximum matching partial at the first time instead of auto-completing to the first match. git-svn-id: svn+ssh://svn.code.sf.net/p/quakespasm/code/trunk@64 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
parent
e33c4e7b37
commit
76e99b804e
1 changed files with 44 additions and 9 deletions
|
@ -749,9 +749,35 @@ AddToTabList -- johnfitz
|
||||||
tablist is a doubly-linked loop, alphabetized by name
|
tablist is a doubly-linked loop, alphabetized by name
|
||||||
============
|
============
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// bash_partial is the string that can be expanded,
|
||||||
|
// aka Linux Bash shell. -- S.A.
|
||||||
|
static char bash_partial[80];
|
||||||
|
static qboolean bash_singlematch;
|
||||||
|
|
||||||
void AddToTabList (char *name, char *type)
|
void AddToTabList (char *name, char *type)
|
||||||
{
|
{
|
||||||
tab_t *t,*insert;
|
tab_t *t,*insert;
|
||||||
|
char *i_bash, *i_name;
|
||||||
|
|
||||||
|
if (!*bash_partial)
|
||||||
|
{
|
||||||
|
strncpy (bash_partial, name, 79);
|
||||||
|
bash_partial[79] = '\0';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bash_singlematch = 0;
|
||||||
|
// find max common between bash_partial and name
|
||||||
|
i_bash = bash_partial;
|
||||||
|
i_name = name;
|
||||||
|
while (*i_bash && (*i_bash == *i_name))
|
||||||
|
{
|
||||||
|
i_bash++;
|
||||||
|
i_name++;
|
||||||
|
}
|
||||||
|
*i_bash = 0;
|
||||||
|
}
|
||||||
|
|
||||||
t = Hunk_Alloc(sizeof(tab_t));
|
t = Hunk_Alloc(sizeof(tab_t));
|
||||||
t->name = name;
|
t->name = name;
|
||||||
|
@ -803,6 +829,9 @@ void BuildTabList (char *partial)
|
||||||
tablist = NULL;
|
tablist = NULL;
|
||||||
len = strlen(partial);
|
len = strlen(partial);
|
||||||
|
|
||||||
|
bash_partial[0] = 0;
|
||||||
|
bash_singlematch = 1;
|
||||||
|
|
||||||
for (cvar=cvar_vars ; cvar ; cvar=cvar->next)
|
for (cvar=cvar_vars ; cvar ; cvar=cvar->next)
|
||||||
if (!Q_strncmp (partial, cvar->name, len))
|
if (!Q_strncmp (partial, cvar->name, len))
|
||||||
AddToTabList (cvar->name, "cvar");
|
AddToTabList (cvar->name, "cvar");
|
||||||
|
@ -864,16 +893,22 @@ void Con_TabComplete (void)
|
||||||
if (!tablist)
|
if (!tablist)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//print list
|
// print list if length > 1
|
||||||
t = tablist;
|
if (tablist->next != tablist)
|
||||||
do
|
|
||||||
{
|
{
|
||||||
Con_SafePrintf(" %s (%s)\n", t->name, t->type);
|
t = tablist;
|
||||||
t = t->next;
|
Con_SafePrintf("\n");
|
||||||
} while (t != tablist);
|
do
|
||||||
|
{
|
||||||
|
Con_SafePrintf(" %s (%s)\n", t->name, t->type);
|
||||||
|
t = t->next;
|
||||||
|
} while (t != tablist);
|
||||||
|
Con_SafePrintf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
//get first match
|
// match = tablist->name;
|
||||||
match = tablist->name;
|
// First time, just show maximum matching chars -- S.A.
|
||||||
|
match = bash_partial;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -903,7 +938,7 @@ void Con_TabComplete (void)
|
||||||
key_linepos = c - key_lines[edit_line] + Q_strlen(match); //set new cursor position
|
key_linepos = c - key_lines[edit_line] + Q_strlen(match); //set new cursor position
|
||||||
|
|
||||||
// if cursor is at end of string, let's append a space to make life easier
|
// if cursor is at end of string, let's append a space to make life easier
|
||||||
if (key_lines[edit_line][key_linepos] == 0)
|
if (key_lines[edit_line][key_linepos] == 0 && bash_singlematch)
|
||||||
{
|
{
|
||||||
key_lines[edit_line][key_linepos] = ' ';
|
key_lines[edit_line][key_linepos] = ' ';
|
||||||
key_linepos++;
|
key_linepos++;
|
||||||
|
|
Loading…
Reference in a new issue