# HG changeset patch # User František Kučera # Date 1430691153 -7200 # Node ID 870b868b6b570b87a1102d4869716a31c01eb105 # Parent 145b45ef77510aabc401395a842f4118e800c78b move formatting logic to output modules diff -r 145b45ef7751 -r 870b868b6b57 c++/parameter-lister/CLI.cpp --- a/c++/parameter-lister/CLI.cpp Sun May 03 23:41:43 2015 +0200 +++ b/c++/parameter-lister/CLI.cpp Mon May 04 00:12:33 2015 +0200 @@ -25,10 +25,6 @@ } } -void process(shared_ptr om) { - om->process(cout); -} - } } } @@ -46,16 +42,7 @@ args.push_back(argv[i]); } - for_each(args.begin(), args.end(), [command, fgGreen, fgReset](string s) { - cout << fgGreen << command << fgReset << ": " << s << endl; - }); - - - for (int i = 0; i < args.size(); i++) { - string s = args[i]; - cout << i + 1 << ":" << s.length() << " = \"" << s << "\"" << endl; - } - + /** Load environment variable */ { string envName = args[0]; boost::optional outputModule = getenv(envName); @@ -67,14 +54,15 @@ } } + /** Do formatting */ { shared_ptr om(new OutputModule()); shared_ptr tom(new TerminalOutputModule()); shared_ptr o(new TerminalOutputModule()); - process(om); - process(tom); - process(o); + om->process(cout, command, args); + tom->process(cout, command, args); + o->process(cout, command, args); } return 0; diff -r 145b45ef7751 -r 870b868b6b57 c++/parameter-lister/info/globalcode/parameterLister/OutputModule.cpp --- a/c++/parameter-lister/info/globalcode/parameterLister/OutputModule.cpp Sun May 03 23:41:43 2015 +0200 +++ b/c++/parameter-lister/info/globalcode/parameterLister/OutputModule.cpp Mon May 04 00:12:33 2015 +0200 @@ -1,4 +1,7 @@ +#include + #include "OutputModule.h" +#include "terminalCodes/TerminalCodes.h" namespace info { namespace globalcode { @@ -13,8 +16,19 @@ OutputModule::~OutputModule() { } -void OutputModule::process(std::ostream &output) { - output << "OutputModule!" << std::endl; +void OutputModule::process(std::ostream &output, std::string &command, std::vector &args) { + terminalCodes::Modifier fgGreen(terminalCodes::FG_GREEN); + terminalCodes::Modifier fgReset(terminalCodes::FG_DEFAULT); + + using namespace std; + + output << "" << endl; + + for_each(args.begin(), args.end(), [command, fgGreen, fgReset](string s) { + cout << fgGreen << command << fgReset << ": " << s << endl; + }); + + output << "" << endl; } diff -r 145b45ef7751 -r 870b868b6b57 c++/parameter-lister/info/globalcode/parameterLister/OutputModule.h --- a/c++/parameter-lister/info/globalcode/parameterLister/OutputModule.h Sun May 03 23:41:43 2015 +0200 +++ b/c++/parameter-lister/info/globalcode/parameterLister/OutputModule.h Mon May 04 00:12:33 2015 +0200 @@ -2,6 +2,7 @@ #define OUTPUTMODULE_H #include +#include namespace info { namespace globalcode { @@ -12,7 +13,7 @@ OutputModule(); OutputModule(const OutputModule& orig); virtual ~OutputModule(); - virtual void process(std::ostream &output); + virtual void process(std::ostream &output, std::string &command, std::vector &args); private: }; diff -r 145b45ef7751 -r 870b868b6b57 c++/parameter-lister/info/globalcode/parameterLister/TerminalOutputModule.cpp --- a/c++/parameter-lister/info/globalcode/parameterLister/TerminalOutputModule.cpp Sun May 03 23:41:43 2015 +0200 +++ b/c++/parameter-lister/info/globalcode/parameterLister/TerminalOutputModule.cpp Mon May 04 00:12:33 2015 +0200 @@ -13,8 +13,16 @@ TerminalOutputModule::~TerminalOutputModule() { } -void TerminalOutputModule::process(std::ostream &output) { - output << "TerminalOutputModule!" << std::endl; +void TerminalOutputModule::process(std::ostream &output, std::string &command, std::vector &args) { + using namespace std; + output << "" << endl; + + for (int i = 0; i < args.size(); i++) { + string s = args[i]; + cout << i + 1 << ":" << s.length() << " = \"" << s << "\"" << endl; + } + + output << "" << endl; } } diff -r 145b45ef7751 -r 870b868b6b57 c++/parameter-lister/info/globalcode/parameterLister/TerminalOutputModule.h --- a/c++/parameter-lister/info/globalcode/parameterLister/TerminalOutputModule.h Sun May 03 23:41:43 2015 +0200 +++ b/c++/parameter-lister/info/globalcode/parameterLister/TerminalOutputModule.h Mon May 04 00:12:33 2015 +0200 @@ -14,7 +14,7 @@ TerminalOutputModule(); TerminalOutputModule(const TerminalOutputModule& orig); virtual ~TerminalOutputModule(); - virtual void process(std::ostream &output); + virtual void process(std::ostream &output, std::string &command, std::vector &args); private: }; diff -r 145b45ef7751 -r 870b868b6b57 c++/parameter-lister/info/globalcode/parameterLister/terminalCodes/TerminalCodes.h --- a/c++/parameter-lister/info/globalcode/parameterLister/terminalCodes/TerminalCodes.h Sun May 03 23:41:43 2015 +0200 +++ b/c++/parameter-lister/info/globalcode/parameterLister/terminalCodes/TerminalCodes.h Mon May 04 00:12:33 2015 +0200 @@ -1,5 +1,5 @@ -#ifndef COLORZ_H -#define COLORZ_H +#ifndef TERMINALCODES_H +#define TERMINALCODES_H #include @@ -37,5 +37,5 @@ } } -#endif /* COLORZ_H */ +#endif /* TERMINALCODES_H */