Add color output
authorDralagen <dralagen@dralagen.fr>
Wed, 27 Nov 2013 08:40:20 +0000 (09:40 +0100)
committerDralagen <dralagen@dralagen.fr>
Wed, 27 Nov 2013 08:40:20 +0000 (09:40 +0100)
src/ColorTerm.hpp [new file with mode: 0644]
src/main.cpp

diff --git a/src/ColorTerm.hpp b/src/ColorTerm.hpp
new file mode 100644 (file)
index 0000000..863ec36
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef COLORTERM_HPP
+#define COLORTERM_HPP
+
+#include <ostream>
+
+namespace ColorTerm {
+       enum Code {
+               FG_RED      = 31,
+               FG_GREEN    = 32,
+               FG_BLUE     = 34,
+               FG_DEFAULT  = 39,
+               BG_RED      = 41,
+               BG_GREEN    = 42,
+               BG_BLUE     = 44,
+               BG_DEFAULT  = 49
+       };
+       class Edit {
+               Code code;
+               public:
+               Edit(Code pCode) : code(pCode) {}
+               friend std::ostream& operator<<(std::ostream& os, const Edit& color) {
+                               return os << "\033[" << color.code << "m";
+                       }
+       };
+
+}
+#endif /* COLORTERM_HPP */
+
index b67e0a7..ff013d0 100644 (file)
@@ -1,5 +1,7 @@
 #include <iostream>
 
+#include "ColorTerm.hpp"
+
 #include "Labyrinth.hpp"
 #include "Game.hpp"
 
@@ -12,6 +14,10 @@ int main(int argc, char **argv)
        int tailleX,tailleY;
        string name;
 
+       ColorTerm::Edit blue(ColorTerm::FG_BLUE);
+       ColorTerm::Edit reset(ColorTerm::FG_DEFAULT);
+
+       cout << blue;
        if (argc == 3) {
                tailleX = stoi(argv[1]);
                tailleY = stoi(argv[2]);
@@ -35,6 +41,7 @@ int main(int argc, char **argv)
                cout << "Nom du personnage : ";
                cin >> name;
        }
+       cout << reset;
        Game g(name, tailleX, tailleY);
 
        g.launch();