C++ (Qt)#ifndef __DEBUGLOG_H__#define __DEBUGLOG_H__ #include <QDebug> void rtLogMessageOutput( QtMsgType type, const char * msg ); #endif // __DEBUGLOG_H__
C++ (Qt) #include "DebugLog.h" void rtLogMessageOutput( QtMsgType type, const char * msg ){ // Для раскраски вывода в консоль использованы ESC последовательности, как это будет работать в Windows не изветсно // если ESC последовательности не будут корректно обрабатываться прийдется их сделать через #ifdef Q_OS_LINUX // PS1 - переменная окружения определяющая строку запроса, вся информация по используемым ESC последовательностям // может быть найдена в хелпе по ней // PS1='\e[0m' ------ сброс // PS1='\e[31m' ------ установка красного цвета текста switch (type) { case QtDebugMsg: fprintf(stdout, "(II): %s\n", msg); break; case QtWarningMsg: fprintf(stdout, "\e[32m(WW): %s\e[0m\n", msg); break; case QtCriticalMsg: fprintf(stdout, "\e[31m(EE): %s\e[0m\n", msg); break; case QtFatalMsg: fprintf(stdout, "\e[41m(FATAL): %s\e[0m\n", msg ); abort(); }} /*Set Display AttributesSet Attribute Mode <ESC>[{attr1};...;{attrn}mSets multiple display attribute settings. The following lists standard attributes:0 Reset all attributes1 Bright2 Dim4 Underscore5 Blink7 Reverse8 Hidden Foreground Colours30 Black31 Red32 Green33 Yellow34 Blue35 Magenta36 Cyan37 White Background Colours40 Black41 Red42 Green43 Yellow44 Blue45 Magenta46 Cyan47 White */
C++ (Qt)// color your text in Windows console mode// colors are 0=black 1=blue 2=green and so on to 15=white // colorattribute = foreground + background * 16// to get red text on yellow use 4 + 14*16 = 228// light red on yellow would be 12 + 14*16 = 236// a Dev-C++ tested console application by vegaseat 07nov2004 #include <iostream>#include <windows.h> // WinApi header using namespace std; // std::cout, std::cin int main(){ HANDLE hConsole; int k; hConsole = GetStdHandle(STD_OUTPUT_HANDLE); // you can loop k higher to see more color choices for(k = 1; k < 255; k++) { // pick the colorattribute k you want SetConsoleTextAttribute(hConsole, k); cout << k << " I want to be nice today!" << endl; } cin.get(); // wait return 0;}
C++ (Qt)#ifndef __COLOURS_HPP__ #define __COLOURS_HPP__ #if defined(linux) || defined(__linux) || defined(__linux__) #define C_LIGHTBLACK 30 #define C_LIGHTRED 31 #define C_LIGHTGREEN 32 #define C_LIGHTYELLOW 33 #define C_LIGHTBLUE 34 #define C_LIGHTPURPLE 35 #define C_LIGHTCYAN 36 #define C_LIGHTWHITE 37 #define C_BACKBLACK 40 #define C_BACKRED 41 #define C_BACKGREEN 42 #define C_BACKYELLOW 43 #define C_BACKBLUE 44 #define C_BACKPURPLE 45 #define C_BACKCYAN 46 #define C_BACKWHITE 47 #define C_DEFAULT 0 #define C_BRIGHT 1 #define C_BLINK 5 #endif #if defined(__WIN32__) || defined(WIN) || defined(WIN32) #define C_LIGHTBLACK 0 #define C_LIGHTRED 4 #define C_LIGHTGREEN 2 #define C_LIGHTYELLOW 14 #define C_LIGHTBLUE 1 #define C_LIGHTPURPLE 5 #define C_LIGHTCYAN 11 #define C_LIGHTWHITE 15 #define C_BACKBLACK 0 #define C_BACKRED 4 #define C_BACKGREEN 2 #define C_BACKYELLOW 14 #define C_BACKBLUE 1 #define C_BACKPURPLE 5 #define C_BACKCYAN 11 #define C_BACKWHITE 15 #define C_DEFAULT 0 #define C_BRIGHT +8 #define C_BLINK 6 #endif #ifdef __cplusplus #if defined(linux) || defined(__linux) || defined(__linux__) #define COLOURF(cletter) "\033[" << cletter << "m" #define COLOURFB(cletter,background) "\033[" << cletter << "," << background << "m" #define CRESET() "\033[0m" #endif #if defined(__WIN32__) || defined(WIN) || defined(WIN32) #define COLOURF(cletter) ""; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),cletter); std::cout #define COLOURFB(cletter,background) ""; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),background*16+cletter); std::cout #define CRESET() ""; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),15); std::cout #endif #else #if defined(linux) || defined(__linux) || defined(__linux__) #define COLOURF(cletter) printf("\033[%dm",cletter); #define COLOURFB(cletter,background) printf("\033[%d,%dm",cletter,background); #define CRESET() printf("\033[0m"); #endif #if defined(__WIN32__) || defined(WIN) || defined(WIN32) #define COLOURF(cletter) ""; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),cletter); std::cout #define COLOURFB(cletter,background) ""; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),background*16+cletter); std::cout #define CRESET() ""; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),15); std::cout #endif #endif #endif
C++ (Qt) OriginalColors = ConsoleInfo.wAttributes; SetConsoleTextAttribute(hConsoleHandle, color);
C++ (Qt) SetConsoleTextAttribute(hConsoleHandle, OriginalColors);
C++ (Qt) HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO *info; int atr; if (GetConsoleScreenBufferInfo(console, info)){ atr = info->wAttributes; fprintf(stdout, "getConsoleAtr = %d\n", atr); }else{ int err = GetLastError(); fprintf(stdout, "getConsoleAtr ERROR = %d\n", err); }
C++ (Qt)CONSOLE_SCREEN_BUFFER_INFO *info;
C++ (Qt)CONSOLE_SCREEN_BUFFER_INFO info;...GetConsoleScreenBufferInfo(console, &info)