c++: some colors + start script
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 11 Sep 2016 00:00:21 +0200
changeset 266e5c4e267ddb
parent 25 584f60104c13
child 27 f08e42c1efc0
c++: some colors + start script
c++/parameter-lister/info/globalcode/parameterLister/TerminalOutputModule.cpp
c++/parameter-lister/info/globalcode/parameterLister/TerminalOutputModule.h
c++/parameter-lister/start.sh
     1.1 --- a/c++/parameter-lister/info/globalcode/parameterLister/TerminalOutputModule.cpp	Sat Sep 10 23:52:37 2016 +0200
     1.2 +++ b/c++/parameter-lister/info/globalcode/parameterLister/TerminalOutputModule.cpp	Sun Sep 11 00:00:21 2016 +0200
     1.3 @@ -13,13 +13,13 @@
     1.4  	terminalCodes::Modifier fgGreen(terminalCodes::FG_GREEN);
     1.5  	terminalCodes::Modifier fgReset(terminalCodes::FG_DEFAULT);
     1.6  	
     1.7 -	output << fgGreen << "<terminalOutputModule>" << fgReset << endl;
     1.8 +	output << fgGreen << "terminalOutputModule >>>" << fgReset << endl;
     1.9  	
    1.10  	for_each(args.begin(), args.end(), [this, &output, command, fgGreen, fgReset](string s) {
    1.11 -		output << fgGreen << command << fgReset << ": " << escapeValue(s, true) << endl;
    1.12 +		output << fgGreen << colorize(RED, command) << fgReset << ": " << escapeValue(s, true) << endl;
    1.13  	});
    1.14  	
    1.15 -	output << fgGreen << "</terminalOutputModule>" << fgReset << endl;
    1.16 +	output << fgGreen << "<<< terminalOutputModule" << fgReset << endl;
    1.17  	
    1.18  	return 0;
    1.19  }
     2.1 --- a/c++/parameter-lister/info/globalcode/parameterLister/TerminalOutputModule.h	Sat Sep 10 23:52:37 2016 +0200
     2.2 +++ b/c++/parameter-lister/info/globalcode/parameterLister/TerminalOutputModule.h	Sun Sep 11 00:00:21 2016 +0200
     2.3 @@ -1,7 +1,8 @@
     2.4  #ifndef TERMINALOUTPUTMODULE_H
     2.5 -#define	TERMINALOUTPUTMODULE_H
     2.6 +#define TERMINALOUTPUTMODULE_H
     2.7  
     2.8  #include <iostream>
     2.9 +#include <sstream>
    2.10  
    2.11  #include "OutputModule.h"
    2.12  
    2.13 @@ -9,16 +10,30 @@
    2.14  namespace globalcode {
    2.15  namespace parameterLister {
    2.16  
    2.17 +using namespace std;
    2.18 +
    2.19  class TerminalOutputModule : public OutputModule {
    2.20  public:
    2.21 -	virtual int process(std::ostream &output, std::string &command, std::vector<std::string> &args);
    2.22 +	virtual int process(ostream &output, string &command, vector<string> &args);
    2.23  private:
    2.24  
    2.25 +	const int RED = 31;
    2.26 +	const int GREEN = 32;
    2.27 +	const int BLUE = 34;
    2.28 +
    2.29 +	string colorize(int foreground, string text) {
    2.30 +		//return "\033[" + "32" + "m" + text + "\033[39m";
    2.31 +		ostringstream fgStream;
    2.32 +		fgStream << foreground;
    2.33 +		return "\033[" + fgStream.str() + "m" + text + "\033[39m";
    2.34 +	}
    2.35 +
    2.36 +	// tabulky: http://www.rubydoc.info/gems/terminal-table/1.4.2/frames
    2.37  };
    2.38  
    2.39  }
    2.40  }
    2.41  }
    2.42  
    2.43 -#endif	/* TERMINALOUTPUTMODULE_H */
    2.44 +#endif /* TERMINALOUTPUTMODULE_H */
    2.45  
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/c++/parameter-lister/start.sh	Sun Sep 11 00:00:21 2016 +0200
     3.3 @@ -0,0 +1,14 @@
     3.4 +#!/bin/sh
     3.5 +
     3.6 +# syntax highlight:
     3.7 +# ./start.sh | pygmentize -l xml
     3.8 +
     3.9 +p1="aaa";
    3.10 +p2="first line
    3.11 +second line
    3.12 +third line";
    3.13 +p3="a & b >> OMG <<";
    3.14 +
    3.15 +export PARAMETER_LISTER_OUTPUT="terminal";
    3.16 +
    3.17 +dist/Debug/GNU-Linux/parameter-lister "$p1" "$p2" "$p3";