| 244 | } |
| 245 | |
| 246 | bool C_TabCompleteList () |
| 247 | { |
| 248 | int nummatches, i; |
| 249 | size_t maxwidth; |
| 250 | int commonsize = INT_MAX; |
| 251 | |
| 252 | nummatches = 0; |
| 253 | maxwidth = 0; |
| 254 | |
| 255 | auto CmdLineText = CmdLine.GetText(); |
| 256 | for (i = TabPos; i < (int)TabCommands.Size(); ++i) |
| 257 | { |
| 258 | if (FindDiffPoint (TabCommands[i].TabName, &CmdLineText[TabStart]) < TabSize) |
| 259 | { |
| 260 | break; |
| 261 | } |
| 262 | else |
| 263 | { |
| 264 | if (i > TabPos) |
| 265 | { |
| 266 | // This keeps track of the longest common prefix for all the possible |
| 267 | // completions, so we can fill in part of the command for the user if |
| 268 | // the longest common prefix is longer than what the user already typed. |
| 269 | int diffpt = FindDiffPoint (TabCommands[i-1].TabName, TabCommands[i].TabName.GetChars()); |
| 270 | if (diffpt < commonsize) |
| 271 | { |
| 272 | commonsize = diffpt; |
| 273 | } |
| 274 | } |
| 275 | nummatches++; |
| 276 | maxwidth = max (maxwidth, strlen (TabCommands[i].TabName.GetChars())); |
| 277 | } |
| 278 | } |
| 279 | if (nummatches > 1) |
| 280 | { |
| 281 | size_t x = 0; |
| 282 | maxwidth += 3; |
| 283 | Printf (TEXTCOLOR_BLUE "Completions for %s:\n", CmdLineText.GetChars()); |
| 284 | for (i = TabPos; nummatches > 0; ++i, --nummatches) |
| 285 | { |
| 286 | // [Dusk] Print console commands blue, CVars green, aliases red. |
| 287 | const char* colorcode = ""; |
| 288 | FConsoleCommand* ccmd; |
| 289 | if (FindCVar (TabCommands[i].TabName.GetChars(), NULL)) |
| 290 | colorcode = TEXTCOLOR_GREEN; |
| 291 | else if ((ccmd = FConsoleCommand::FindByName (TabCommands[i].TabName.GetChars())) != NULL) |
| 292 | { |
| 293 | if (ccmd->IsAlias()) |
| 294 | colorcode = TEXTCOLOR_RED; |
| 295 | else |
| 296 | colorcode = TEXTCOLOR_LIGHTBLUE; |
| 297 | } |
| 298 | |
| 299 | Printf ("%s%-*s", colorcode, int(maxwidth), TabCommands[i].TabName.GetChars()); |
| 300 | x += maxwidth; |
| 301 | if (x > CmdLine.ConCols / active_con_scale(twod) - maxwidth) |
| 302 | { |
| 303 | x = 0; |
no test coverage detected