MCPcopy Create free account
hub / github.com/Raais/ImStudio / ExampleAppConsole

Class ExampleAppConsole

src/third-party/imgui/imgui_demo.cpp:6459–6516  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6457// Demonstrate creating a simple console window, with scrolling, filtering, completion and history.
6458// For the console example, we are using a more C++ like approach of declaring a class to hold both data and functions.
6459struct ExampleAppConsole
6460{
6461 char InputBuf[256];
6462 ImVector<char*> Items;
6463 ImVector<const char*> Commands;
6464 ImVector<char*> History;
6465 int HistoryPos; // -1: new line, 0..History.Size-1 browsing history.
6466 ImGuiTextFilter Filter;
6467 bool AutoScroll;
6468 bool ScrollToBottom;
6469
6470 ExampleAppConsole()
6471 {
6472 IMGUI_DEMO_MARKER("Examples/Console");
6473 ClearLog();
6474 memset(InputBuf, 0, sizeof(InputBuf));
6475 HistoryPos = -1;
6476
6477 // "CLASSIFY" is here to provide the test case where "C"+[tab] completes to "CL" and display multiple matches.
6478 Commands.push_back("HELP");
6479 Commands.push_back("HISTORY");
6480 Commands.push_back("CLEAR");
6481 Commands.push_back("CLASSIFY");
6482 AutoScroll = true;
6483 ScrollToBottom = false;
6484 AddLog("Welcome to Dear ImGui!");
6485 }
6486 ~ExampleAppConsole()
6487 {
6488 ClearLog();
6489 for (int i = 0; i < History.Size; i++)
6490 free(History[i]);
6491 }
6492
6493 // Portable helpers
6494 static int Stricmp(const char* s1, const char* s2) { int d; while ((d = toupper(*s2) - toupper(*s1)) == 0 && *s1) { s1++; s2++; } return d; }
6495 static int Strnicmp(const char* s1, const char* s2, int n) { int d = 0; while (n > 0 && (d = toupper(*s2) - toupper(*s1)) == 0 && *s1) { s1++; s2++; n--; } return d; }
6496 static char* Strdup(const char* s) { IM_ASSERT(s); size_t len = strlen(s) + 1; void* buf = malloc(len); IM_ASSERT(buf); return (char*)memcpy(buf, (const void*)s, len); }
6497 static void Strtrim(char* s) { char* str_end = s + strlen(s); while (str_end > s && str_end[-1] == ' ') str_end--; *str_end = 0; }
6498
6499 void ClearLog()
6500 {
6501 for (int i = 0; i < Items.Size; i++)
6502 free(Items[i]);
6503 Items.clear();
6504 }
6505
6506 void AddLog(const char* fmt, ...) IM_FMTARGS(2)
6507 {
6508 // FIXME-OPT
6509 char buf[1024];
6510 va_list args;
6511 va_start(args, fmt);
6512 vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args);
6513 buf[IM_ARRAYSIZE(buf)-1] = 0;
6514 va_end(args);
6515 Items.push_back(Strdup(buf));
6516 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected