Conversation
…for colorizing command line output (on Linux) is esablished
…Colorizer Objects. (enables colorizer calls in functions with std::string expection)
| //If we are on windows, get the "default" console color and safe it in _defcolor | ||
| #if defined(_WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) | ||
| CONSOLE_SCREEN_BUFFER_INFO Info; | ||
| HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE); |
There was a problem hiding this comment.
weird var-name
| HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE); | |
| HANDLE std_out_handler = GetStdHandle(STD_OUTPUT_HANDLE); |
|
|
||
|
|
||
|
|
||
| template <typename T = std::string> |
There was a problem hiding this comment.
why a template if it's always a string
There was a problem hiding this comment.
its not always a string, the default valueis a string. It has to accept all types, that work with the << operator.
I had to define the default type allready in the Template. Just writing the default in the Attributes wouldn't be accepted.
| this->_input.str(""); | ||
| this->_input << s; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| "Either provide a full filepath or fix your PATH environment!" + | ||
| (p.required ? "" : " Since this file is not strictly required, you might also pass the empty string \"\" as " | ||
| "argument to prevent its usage (this might limit the usability of the tool).")); | ||
| "argument to prevent it's usage (this might limit the usability of the tool).")); |
There was a problem hiding this comment.
ddint know I changed it. yes, old one is correct
| /// Copy constructor | ||
| //Colorizer(const Colorizer &rhs); |
There was a problem hiding this comment.
make explicit
= delete
or
= default
| CONSOLE_SCREEN_BUFFER_INFO Info; | ||
| HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE); | ||
| GetConsoleScreenBufferInfo(hStdout, &Info); | ||
| _defcolor = Info.wAttributes; |
There was a problem hiding this comment.
remember two default colors, for cerr and cout
| //If we are on windows, get the "default" console color and safe it in _defcolor | ||
| #if defined(_WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) | ||
| CONSOLE_SCREEN_BUFFER_INFO Info; | ||
| HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE); | ||
| GetConsoleScreenBufferInfo(hStdout, &Info); | ||
| _defcolor = Info.wAttributes; |
There was a problem hiding this comment.
move this to another class (construction + destrcution)
namespace OpenMS
{
namespace Internal
{
struct WindowsOSDefaultColor
{
WindowsOSDefaultColor()
{
std::cout << "saving default colors...\n";
/// get and remember 2 default colors
}
~WindowsOSDefaultColor()
{
std::cout << "restoring default colors...\n";
}
int default_cerr_;
int default_cout_;
}; // end WindowsOSDefaultColor
extern static const WindowsOSDefaultColor default_color____;
} // internal
} // OpenMS
| auto Colorizer::getColor(int i) | ||
| { | ||
| //checking if parameter is outside array size or not set at all | ||
| // Darf nicht NULL, da dadurch kein "black" mehr möglich ist | ||
| return ((i == -1 || i > 8 || i < 0) ? this->colors[this->_color] : this->colors[i]); | ||
| } | ||
|
|
||
| std::string Colorizer::getText() | ||
| { | ||
|
|
||
| return _input.str(); | ||
| } |
| // overload the shift operator (<<) | ||
| std::ostream &operator<<(std::ostream &o_stream, OpenMS::Colorizer& col) |
There was a problem hiding this comment.
| // overload the shift operator (<<) | |
| std::ostream &operator<<(std::ostream &o_stream, OpenMS::Colorizer& col) | |
| // overload the shift operator (<<) | |
| std::ostream &operator<<(std::ostream &o_stream, OpenMS::Colorizer& col) | |
| { | |
| col.outputToStream(o_stream); | |
| return o_stream; | |
| } |
| // colorize string with color set in the object | ||
| #if defined(_WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) | ||
|
|
||
| //set color of output | ||
| SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),col.getColor()); | ||
|
|
||
| // paste text | ||
| o_stream << col.getText(); | ||
|
|
||
| // recover old Console font and set it as new one. | ||
| if(col.getReset()) | ||
| { | ||
| SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), col._defcolor); |
There was a problem hiding this comment.
move to Colorizer::outputToStream(std::ostream&);
Changes made in pull request code review. Not working, will be fixed by next commit. Co-authored-by: Chris Bielow <chris.bielow@fu-berlin.de> Co-authored-by: Lenny Kovac <44415793+lennykovac@users.noreply.github.com> Co-authored-by: hbeschorner <102038306+hbeschorner@users.noreply.github.com>
…nality will be set with next commit
…olor inside function call
…ows not tested). Basics of IndentedStringStream implemented.
…breakstring func. keine Testklassen
Co-authored-by: Chris Bielow <chris.bielow@fu-berlin.de>
Co-authored-by: Chris Bielow <chris.bielow@fu-berlin.de>
Co-authored-by: Chris Bielow <chris.bielow@fu-berlin.de>
Co-authored-by: Chris Bielow <chris.bielow@fu-berlin.de>
Co-authored-by: Chris Bielow <chris.bielow@fu-berlin.de>
Co-authored-by: Chris Bielow <chris.bielow@fu-berlin.de>
Description
Added an interface to enable coloring the console output.
Important are the classes Colorizer (Colorizer.ccp & Colorizer.h).
Changes in TOPPBasse and other classes are just for testing and not final in any way right now.
Checklist:
How can I get additional information on failed tests during CI:
If your PR is failing you can check out
Note:
Advanced commands (admins / reviewer only):
/reformat(experimental) applies the clang-format style changes as additional commitrebuild jenkinswill retrigger Jenkins-based CI builds