添加windows 支持,不完整。

This commit is contained in:
unlockable
2023-06-24 17:11:22 +08:00
parent 3de33ec9ab
commit 591f675027
11 changed files with 143 additions and 49 deletions

View File

@@ -1,11 +1,16 @@
#include "Tools.hpp"
#include <string>
#ifdef __API_AVAILABLE_PLATFORM_macosx
#ifdef __APPLE__
#include <sys/ioctl.h>
#include <unistd.h>
#endif
#if defined _WIN64 || defined _WIN32
#include <windows.h>
#include <conio.h>
#endif
using namespace ConsoleColorTool;
setoutputcolor::setoutputcolor(ConsoleColors _color)
@@ -128,7 +133,7 @@ const std::string setMiddle(const std::string str, const int targetLength,
return result;
}
#ifdef __API_AVAILABLE_PLATFORM_macosx
#ifdef __APPLE__
void clearScreen() {
system("clear");
}
@@ -165,6 +170,34 @@ const termSize getConsoleSize() {
}
#endif
#if defined _WIN64 || defined _WIN32
void clearScreen() {
std::cout << "\x1B[2J\x1B[H" << std::flush;
}
void disableEchoBack() {
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode = 0;
GetConsoleMode(hStdin, &mode);
SetConsoleMode(hStdin, mode & (~ENABLE_ECHO_INPUT) & (~ENABLE_LINE_INPUT) & (~ENABLE_PROCESSED_INPUT));
}
void enableEchoBack() {
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode = 0;
GetConsoleMode(hStdin, &mode);
SetConsoleMode(hStdin, mode | (ENABLE_ECHO_INPUT) | (ENABLE_LINE_INPUT) | (ENABLE_PROCESSED_INPUT));
}
const termSize getConsoleSize() {
CONSOLE_SCREEN_BUFFER_INFO scrInfo;
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hStdout, &scrInfo);
return termSize{ .width=scrInfo.dwSize.X, .height=scrInfo.dwSize.Y };
}
#endif
void backSpace(int num) {
for (int i = 0; i < num; i++) {
std::cout << "\033[D";