From 95ae72454720c5ef6459eacab2ce7f920641980b Mon Sep 17 00:00:00 2001 From: Jared Thomas Date: Wed, 8 Feb 2023 11:30:04 -0500 Subject: [PATCH] Replaced system() for screen clearing --- screen.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/screen.cpp b/screen.cpp index d37cd85..57f59b9 100644 --- a/screen.cpp +++ b/screen.cpp @@ -8,16 +8,28 @@ #include "screen.h" #ifdef PLATFORM_LINUX - #define CLEAR_SCREEN_COMMAND "clear" + #include #endif #ifdef PLATFORM_WINDOWS - #define CLEAR_SCREEN_COMMAND "cls" + #include #endif -#include - void clearScreen() { - system(CLEAR_SCREEN_COMMAND); +#ifdef PLATFORM_LINUX + std::cout << "\033[2J"; + std::cout << "\033[1;1H"; +#endif + +#ifdef PLATFORM_WINDOWS + COORD tl = {0,0}; + CONSOLE_SCREEN_BUFFER_INFO s; + HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE); + GetConsoleScreenBufferInfo(console, &s); + DWORD written, cells = s.dwSize.X * s.dwSize.Y; + FillConsoleOutputCharacter(console, ' ', cells, tl, &written); + FillConsoleOutputAttribute(console, s.wAttributes, cells, tl, &written); + SetConsoleCursorPosition(console, tl); +#endif }