Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b1a399f
working tester class
mariogrenadine May 12, 2022
da8c7dd
funktionierende Testklasse 2
mariogrenadine May 12, 2022
a59a4a9
Added different input tests for Colorizer testclass, suggested bluepr…
mariogrenadine May 17, 2022
7e27de5
Adding changes to colorizer testclass 1
mariogrenadine May 20, 2022
8c04f93
Updated input testing, minor changes
mariogrenadine May 23, 2022
e84062f
Operator test added
mariogrenadine May 23, 2022
437c009
added tests of all methods, but improvement is still needed
mariogrenadine May 23, 2022
6795313
Defined function tests, restructured ifdefs
mariogrenadine May 25, 2022
49b0d2f
Improved public methods tests
mariogrenadine May 25, 2022
3c9f7d7
possibly fixed ConsoleUtils.cpp compilation issue
mariogrenadine Jun 9, 2022
f65e69c
Implemented supressed coloring for Linus when output is fed to a file…
mariogrenadine Jun 15, 2022
8db4024
updated consoleutils testclass, still functionality needed
mariogrenadine Jun 17, 2022
5a63fa3
updated STDOUT exclusion functionality
mariogrenadine Jun 19, 2022
511e334
updated
mariogrenadine Jun 19, 2022
18aa20d
merging protected colorizer and new consoleutils class
mariogrenadine Jun 19, 2022
760a642
updated
mariogrenadine Jun 19, 2022
a77b699
non-working merged code with new suggestions
mariogrenadine Jun 21, 2022
45a6b98
Working merged new Colorizer and ConsoleUtils classes, minor changes …
mariogrenadine Jun 21, 2022
753989b
error fixes
mariogrenadine Jun 21, 2022
16c64b4
updated ConsoleUtils_test functionality, ready for review
mariogrenadine Jun 22, 2022
2e705e1
Merge branch 'develop' into consoleutils_testclass
mariogrenadine Jul 12, 2022
5729987
coltest constructor not compiling
mariogrenadine Sep 25, 2022
7df7560
compiling Colorizer_testclass, test still unsuccessful
mariogrenadine Sep 25, 2022
59e0523
metaupdate 1
mariogrenadine Sep 26, 2022
7ca1e97
dissected Colorizer - problem is in cout, cerr, stream recognition in…
mariogrenadine Sep 27, 2022
de8dfaa
writing ColorizerTester inside Colorizer metavestion
mariogrenadine Sep 28, 2022
c30c7bc
working colorStreamSimple method!
mariogrenadine Sep 28, 2022
4852574
updating Simple class functionality, having problems with private inp…
mariogrenadine Sep 28, 2022
ac7b4a3
ResetColorSimple working but codes are being fed in wrong order
mariogrenadine Sep 28, 2022
989e661
FIRST WORKING TEST
mariogrenadine Sep 28, 2022
733d62e
Working Colorizer_test apart from instances red()
mariogrenadine Sep 28, 2022
7c81896
Working Colorizer test with supress coloring, needs code cleaning
mariogrenadine Sep 29, 2022
97c308c
finished Colorizer, ConsoleUtils Unit tests, ready for PR
mariogrenadine Sep 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 176 additions & 11 deletions src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,46 +35,211 @@
#pragma once

#include <OpenMS/DATASTRUCTURES/String.h>
#include <OpenMS/DATASTRUCTURES/StringListUtils.h>
#include <OpenMS/CONCEPT/Colorizer.h>
#include <iostream>

namespace OpenMS
{

class OPENMS_DLLAPI ConsoleUtils
{
public:
public:
/// make a string console friendly
/// by breaking it into multiple lines according to the console width
/// The 'indentation' gives the number of spaces which is prepended beginning at the second (!)
/// line, so one gets a left aligned block which has some space to the left.
/// An indentation of 0 results in the native console's default behaviour: just break at the end of
/// its width and start a new line.
/// but usually one wants nicely intended blocks, which the console does not support
/// 'max_lines' gives the upper limit of lines returned after breaking is finished.
/// but usually one wants nicely indented blocks, which the console does not support
/// 'max_lines' gives the upper limit of lines returned after breaking is finished.
/// Excess lines are removed and replaced by '...', BUT the last line will be preserved.
/// @param input String to be split
/// @param indentation Number of spaces to use for lines 2 until last line.
/// @param max_lines Limit of output lines (all others are removed)
static String breakString(const String& input, const Size indentation, const Size max_lines);
/// C'tor
ConsoleUtils();

/// Copy C'tor
ConsoleUtils(const ConsoleUtils&);

/// Destructor
~ConsoleUtils();

static OpenMS::String breakString(const String& input,
const Size indentation,
const Size max_lines,
const Size curser_pos = 0);

static OpenMS::StringList breakStringList(const String& input,
const Size indentation,
const Size max_lines,
const Size curser_pos = 0);

int getConsoleSize() //deleted const here
{
return console_width_;
}

static ConsoleUtils getInstance()
{
return getInstance_();
}


//#ifdef OPENMS_WINDOWSPLATFORM

// /// reset the color of the windows output handle
// void resetCoutColor();
// /// reset the color of the windows error handle
// void resetCerrColor();

/// reset the color of both output streams
void resetConsoleColor();

private:
/// width of console we are currently in (if not determinable, set to 80 as default)
void setCoutColor(int color_code);

void setCerrColor(int color_code);

int getCoutColor();

int getCerrColor();

//#endif

private:
/// width of console we are currently in
///(if not determinable, set to 80 as default)
int console_width_;

/// read console settings for output shaping
int readConsoleSize_();


static ConsoleUtils& getInstance_();

/// returns a console friendly version of input
String breakString_(const String& input, const Size indentation, const Size max_lines);
OpenMS::StringList breakString_(const String& input,
const Size indentation,
const Size max_lines,
const Size curser_pos);

/// C'tor
ConsoleUtils();

/// Copy C'tor
ConsoleUtils(const ConsoleUtils &);

// /// Destructor
// ~ConsoleUtils();

/// Assignment operator
void operator=(ConsoleUtils const&);

//#ifdef OPENMS_WINDOWSPLATFORM

/// Default console color for output stream
int default_cout_;

/// Default console color for error stream
int default_cerr_;


//#endif
};

class ColorizerMethods: public Colorizer
{

public:

///Constructor
ColorizerMethods(const Color color);

/// Default destructor
~ColorizerMethods();

void outputToStream_(std::ostream& o_stream){this->outputToStream(o_stream);}

void colorStream_(std::ostream& stream) const{this->colorStream(stream);}

void resetColor_(std::ostream& stream){this->resetColor(stream);}

bool getReset_(){return this->getReset();}

std::string getDataAsString_(){return this->getDataAsString();}
};

class IndentedStringStream
{
public:
IndentedStringStream(std::ostream& stream,
const Size indentation,
const Size max_lines) : stream_(&stream),
indentation_(indentation),
max_lines_(max_lines),
current_column_pos_(0)
{
max_line_width_ = ConsoleUtils::getInstance().getConsoleSize();
}


template<typename T>
IndentedStringStream& operator<<(const T& data)
{

std::stringstream s;
s << data;
const std::string& string_to_print = s.str();

//wie viele zeilen sind es / viel viele zeichen in letrzter zeile

OpenMS::StringList result = ConsoleUtils::breakStringList(string_to_print,
indentation_,
max_lines_,
current_column_pos_);

if (result.size()>=2)
{ // we completed the previous line, so start counting from the latest incomplete line
current_column_pos_ = result.back().size();
}
else
{ // only one line; simply forward the column position
current_column_pos_ += result.back().size();
}



*stream_ << ListUtils::concatenate(result, '\n');

return *this;

}
///741 = offset
///763 = indent


// IndentedStringStream& operator<<(ColorizerMethods& colorizer);

private:
std::ostream* stream_;
int indentation_;
int max_lines_;
int max_line_width_;
int current_column_pos_;


IndentedStringStream& operator<<(ColorizerMethods& colorizer)
{
colorizer.colorStream_(*stream_);
this->operator<<(colorizer.getDataAsString_());

if(colorizer.getReset_())
{
colorizer.resetColor_(*stream_);

}

return *this;
}

};

} // namespace OpenMS

Loading