From 87ea4904a0136564bdb22a95d9fef12282c27624 Mon Sep 17 00:00:00 2001 From: Nils Maier Date: Fri, 15 Nov 2013 00:52:20 +0100 Subject: Implement basic color support for the Windows console Only \033[*m (SGR) is supported, with a 16+16 color terminal. --- src/WinConsoleFile.h | 52 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 15 deletions(-) (limited to 'src/WinConsoleFile.h') diff --git a/src/WinConsoleFile.h b/src/WinConsoleFile.h index ec6f8e26..67312f90 100644 --- a/src/WinConsoleFile.h +++ b/src/WinConsoleFile.h @@ -32,28 +32,50 @@ * files in the program, then also delete it here. */ /* copyright --> */ + #ifndef D_WIN_CONSOLE_FILE_H #define D_WIN_CONSOLE_FILE_H +#include + #include "OutputFile.h" namespace aria2 { -// This is a wrapper class for WriteConsoleW -class WinConsoleFile:public OutputFile { -public: - WinConsoleFile(DWORD stdHandle); - virtual ~WinConsoleFile(); - virtual size_t write(const char* str) CXX11_OVERRIDE; - virtual int vprintf(const char* format, va_list va) CXX11_OVERRIDE; - virtual int flush() CXX11_OVERRIDE; - virtual bool supportsColor() CXX11_OVERRIDE; -private: - DWORD stdHandle_; - // Don't allow copying - WinConsoleFile(const WinConsoleFile&); - WinConsoleFile& operator=(const WinConsoleFile&); -}; + // This is a wrapper class for WriteConsoleW + class WinConsoleFile: public OutputFile + { + public: + WinConsoleFile(DWORD stdHandle); + virtual ~WinConsoleFile() {} + + virtual size_t write(const char* str) CXX11_OVERRIDE; + virtual int vprintf(const char* format, va_list va) CXX11_OVERRIDE; + virtual bool supportsColor() CXX11_OVERRIDE; + virtual int flush() CXX11_OVERRIDE + { + return 0; + } + + private: + DWORD stdHandle_; + bool bold_; + bool underline_; + bool reverse_; + WORD fg_, deffg_; + WORD bg_, defbg_; + + size_t writeColorful(const std::wstring& str); + inline HANDLE handle() const + { + return ::GetStdHandle(stdHandle_); + } + + private: + // Don't allow copying + WinConsoleFile(const WinConsoleFile&) = delete; + WinConsoleFile& operator=(const WinConsoleFile&) = delete; + }; } // namespace aria2 -- cgit