From 0c850e8ddd5fe5c4ae70593d25404e094b17cae2 Mon Sep 17 00:00:00 2001 From: slatenails Date: Sun, 28 Jul 2013 14:58:30 +0300 Subject: [PATCH] Results for console tab-completion are now color-coded. CCMDs appear blue, CVars green and aliases red. --- src/c_console.cpp | 15 ++++++++++++++- src/c_dispatch.cpp | 5 +++++ src/c_dispatch.h | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/c_console.cpp b/src/c_console.cpp index 170cc97d44..0ecd600e4d 100644 --- a/src/c_console.cpp +++ b/src/c_console.cpp @@ -2121,7 +2121,20 @@ static bool C_TabCompleteList () Printf (TEXTCOLOR_BLUE "Completions for %s:\n", CmdLine+2); for (i = TabPos; nummatches > 0; ++i, --nummatches) { - Printf ("%-*s", int(maxwidth), TabCommands[i].TabName.GetChars()); + // [Dusk] Print console commands blue, CVars green, aliases red. + const char* colorcode = ""; + FConsoleCommand* ccmd; + if (FindCVar (TabCommands[i].TabName, NULL)) + colorcode = "\\c[Green]"; + else if ((ccmd = FConsoleCommand::FindByName (TabCommands[i].TabName)) != NULL) + { + if (ccmd->IsAlias()) + colorcode = "\\c[Red]"; + else + colorcode = "\\c[Light Blue]"; + } + + Printf ("%s%-*s", strbin1 (colorcode).GetChars(), int(maxwidth), TabCommands[i].TabName.GetChars()); x += maxwidth; if (x > ConCols - maxwidth) { diff --git a/src/c_dispatch.cpp b/src/c_dispatch.cpp index d253549868..76b6e395df 100644 --- a/src/c_dispatch.cpp +++ b/src/c_dispatch.cpp @@ -955,6 +955,11 @@ bool FConsoleCommand::AddToHash (FConsoleCommand **table) return true; } +FConsoleCommand* FConsoleCommand::FindByName (const char* name) +{ + return FindNameInHashTable (Commands, name, strlen (name)); +} + FConsoleCommand::FConsoleCommand (const char *name, CCmdRun runFunc) : m_RunFunc (runFunc) { diff --git a/src/c_dispatch.h b/src/c_dispatch.h index 12ea559de3..96dc50644e 100644 --- a/src/c_dispatch.h +++ b/src/c_dispatch.h @@ -93,6 +93,7 @@ public: void PrintCommand () { Printf ("%s\n", m_Name); } virtual void Run (FCommandLine &args, APlayerPawn *instigator, int key); + static FConsoleCommand* FindByName (const char* name); FConsoleCommand *m_Next, **m_Prev; char *m_Name;