| 9197 | } |
| 9198 | |
| 9199 | void ExecCommand(const char* command_line) |
| 9200 | { |
| 9201 | AddLog("# %s\n", command_line); |
| 9202 | |
| 9203 | // Insert into history. First find match and delete it so it can be pushed to the back. |
| 9204 | // This isn't trying to be smart or optimal. |
| 9205 | HistoryPos = -1; |
| 9206 | for (int i = History.Size - 1; i >= 0; i--) |
| 9207 | if (Stricmp(History[i], command_line) == 0) |
| 9208 | { |
| 9209 | ImGui::MemFree(History[i]); |
| 9210 | History.erase(History.begin() + i); |
| 9211 | break; |
| 9212 | } |
| 9213 | History.push_back(Strdup(command_line)); |
| 9214 | |
| 9215 | // Process command |
| 9216 | if (Stricmp(command_line, "CLEAR") == 0) |
| 9217 | { |
| 9218 | ClearLog(); |
| 9219 | } |
| 9220 | else if (Stricmp(command_line, "HELP") == 0) |
| 9221 | { |
| 9222 | AddLog("Commands:"); |
| 9223 | for (int i = 0; i < Commands.Size; i++) |
| 9224 | AddLog("- %s", Commands[i]); |
| 9225 | } |
| 9226 | else if (Stricmp(command_line, "HISTORY") == 0) |
| 9227 | { |
| 9228 | int first = History.Size - 10; |
| 9229 | for (int i = first > 0 ? first : 0; i < History.Size; i++) |
| 9230 | AddLog("%3d: %s\n", i, History[i]); |
| 9231 | } |
| 9232 | else |
| 9233 | { |
| 9234 | AddLog("Unknown command: '%s'\n", command_line); |
| 9235 | } |
| 9236 | |
| 9237 | // On command input, we scroll to bottom even if AutoScroll==false |
| 9238 | ScrollToBottom = true; |
| 9239 | } |
| 9240 | |
| 9241 | // In C++11 you'd be better off using lambdas for this sort of forwarding callbacks |
| 9242 | static int TextEditCallbackStub(ImGuiInputTextCallbackData* data) |