| 6790 | } |
| 6791 | |
| 6792 | void ExecCommand(const char* command_line) |
| 6793 | { |
| 6794 | AddLog("# %s\n", command_line); |
| 6795 | |
| 6796 | // Insert into history. First find match and delete it so it can be pushed to the back. |
| 6797 | // This isn't trying to be smart or optimal. |
| 6798 | HistoryPos = -1; |
| 6799 | for (int i = History.Size - 1; i >= 0; i--) |
| 6800 | if (Stricmp(History[i], command_line) == 0) |
| 6801 | { |
| 6802 | free(History[i]); |
| 6803 | History.erase(History.begin() + i); |
| 6804 | break; |
| 6805 | } |
| 6806 | History.push_back(Strdup(command_line)); |
| 6807 | |
| 6808 | // Process command |
| 6809 | if (Stricmp(command_line, "CLEAR") == 0) |
| 6810 | { |
| 6811 | ClearLog(); |
| 6812 | } |
| 6813 | else if (Stricmp(command_line, "HELP") == 0) |
| 6814 | { |
| 6815 | AddLog("Commands:"); |
| 6816 | for (int i = 0; i < Commands.Size; i++) |
| 6817 | AddLog("- %s", Commands[i]); |
| 6818 | } |
| 6819 | else if (Stricmp(command_line, "HISTORY") == 0) |
| 6820 | { |
| 6821 | int first = History.Size - 10; |
| 6822 | for (int i = first > 0 ? first : 0; i < History.Size; i++) |
| 6823 | AddLog("%3d: %s\n", i, History[i]); |
| 6824 | } |
| 6825 | else |
| 6826 | { |
| 6827 | AddLog("Unknown command: '%s'\n", command_line); |
| 6828 | } |
| 6829 | |
| 6830 | // On command input, we scroll to bottom even if AutoScroll==false |
| 6831 | ScrollToBottom = true; |
| 6832 | } |
| 6833 | |
| 6834 | // In C++11 you'd be better off using lambdas for this sort of forwarding callbacks |
| 6835 | static int TextEditCallbackStub(ImGuiInputTextCallbackData* data) |