#include "cpps/cpps.h"namespace cpps{void cpps_console_clearcolor(){#ifdef _WIN32HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleTextAttribute(handle, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);#elseprintf("033円[0m");#endif}void cpps_console_color(cpps_integer color){#ifdef _WIN32WORD tcolor[] = {0, 4,2,6,3,5,11 };HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleTextAttribute(handle, tcolor[color%7]);#elseprintf("033円[%dm", int(color % 7 + 30));#endif}#ifdef _WIN32bool cls() //̷ʽɻĻ{HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);COORD coordScreen = { 0, 0 }; /* here's where we'll home the cursor */DWORD cCharsWritten;CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */DWORD dwConSize; /* number of character cells in the current buffer *//* get the number of character cells in the current buffer */if (!GetConsoleScreenBufferInfo(hConsole, &csbi))return false;dwConSize = csbi.dwSize.X * csbi.dwSize.Y;/* fill the entire screen with blanks */if (!FillConsoleOutputCharacter(hConsole, (TCHAR)' ', dwConSize, coordScreen, &cCharsWritten))return false;/* get the current text attribute */if (!GetConsoleScreenBufferInfo(hConsole, &csbi))return false;/* now set the buffer's attributes accordingly */if (!FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten))return false;/* put the cursor at (0, 0) */if (!SetConsoleCursorPosition(hConsole, coordScreen))return false;return true;}#endifint32 cpps_console_clear(){#ifdef _WIN32return (int32)cls();#elseprintf("033円[2J");return 1;#endif}void cpps_console_cursor(bool visible){#ifdef _WIN32HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);CONSOLE_CURSOR_INFO cci;GetConsoleCursorInfo(hOut, &cci);cci.bVisible = visible;SetConsoleCursorInfo(hOut, &cci);#endif}void cpps_regconsole(C* c){cpps::_module(c,"console")[def("color", cpps_console_color),def("cursor", cpps_console_cursor),def("clearcolor", cpps_console_clearcolor),def("clear", cpps_console_clear)];}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型