Skip to content

Command Line coloring#131

Open
morm24 wants to merge 25 commits intocbielow:developfrom
morm24:coloring
Open

Command Line coloring#131
morm24 wants to merge 25 commits intocbielow:developfrom
morm24:coloring

Conversation

@morm24
Copy link

@morm24 morm24 commented Apr 29, 2022

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:

  • Make sure that you are listed in the AUTHORS file
  • [-] Add relevant changes and new features to the CHANGELOG file
  • I have commented my code, particularly in hard-to-understand areas
  • [-] New and existing unit tests pass locally with my changes
  • [-] Updated or added python bindings for changed or new classes. (Tick if no updates were necessary.)

How can I get additional information on failed tests during CI:

If your PR is failing you can check out

Note:

  • Once you opened a PR try to minimize the number of pushes to it as every push will trigger CI (automated builds and test) and is rather heavy on our infrastructure (e.g., if several pushes per day are performed).

Advanced commands (admins / reviewer only):

  • /reformat (experimental) applies the clang-format style changes as additional commit
  • setting the label "NoJenkins" will skip tests for this PR on jenkins (saves resources e.g., on edits that do not affect tests)
  • commenting with rebuild jenkins will retrigger Jenkins-based CI builds

@morm24 morm24 changed the title COmmand Line coloring Command Line coloring Apr 29, 2022
@cbielow cbielow changed the base branch from develop to AC_DFA April 29, 2022 13:28
@cbielow cbielow changed the base branch from AC_DFA to develop April 29, 2022 13:29
Copy link

@lennykovac lennykovac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall but stick to the coding-convention and a lot of unnecessary spaces/newlines.
Try to stick to english-comments :)

//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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird var-name

Suggested change
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
HANDLE std_out_handler = GetStdHandle(STD_OUTPUT_HANDLE);




template <typename T = std::string>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why a template if it's always a string

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 86 to 87
this->_input.str("");
this->_input << s;

This comment was marked as resolved.

"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)."));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty sure its was correct

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ddint know I changed it. yes, old one is correct

Comment on lines 64 to 65
/// Copy constructor
//Colorizer(const Colorizer &rhs);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make explicit
= delete
or
= default

CONSOLE_SCREEN_BUFFER_INFO Info;
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hStdout, &Info);
_defcolor = Info.wAttributes;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remember two default colors, for cerr and cout

Comment on lines 58 to 63
//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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines 96 to 107
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();
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete

Comment on lines 108 to 109
// overload the shift operator (<<)
std::ostream &operator<<(std::ostream &o_stream, OpenMS::Colorizer& col)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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;
}

Comment on lines 111 to 123
// 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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to Colorizer::outputToStream(std::ostream&);

morm24 and others added 10 commits May 2, 2022 13:28
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>
…ows not tested). Basics of IndentedStringStream implemented.
morm24 and others added 3 commits May 12, 2022 11:47
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>
morm24 and others added 3 commits May 12, 2022 11:51
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants