commit 33db0efce049392b8da82defa4f3b287cf8f5364 Author: Matthew Ellison Date: Fri Mar 23 14:08:20 2018 -0400 Added a class that changes the colors of a terminal diff --git a/TermColors.hpp b/TermColors.hpp new file mode 100644 index 0000000..70e6adf --- /dev/null +++ b/TermColors.hpp @@ -0,0 +1,65 @@ +//Games/Solitaire/HEaders/TermColors.hpp +//Matthew Ellison +// Created: 3-6-18 +//Modified: 3-6-18 +//This file contains the class that helps control the colors presented on the terminal +//It will also aid in printing all of the cards and stacks of cards +//This class uses the ANSI escape sequences to color the terminal + + +#ifndef TERMCOLORS_HPP +#define TERMCOLORS_HPP + +#include +#include + +namespace mee{ + + +enum class textAttributes {ALL_OFF, BOLD, UNDERSCORE = 4, BLINK}; +enum class textColors {BLACK = 30, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE}; +enum class backColors {BLACK = 40, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE}; + + +class TermColors{ +private: +public: + TermColors() + { } + std::string eraseLine() + { return "\033[K"; } + std::string eraseLine(unsigned int row){ + std::stringstream text; + text << "\033[" << row << ";0H\033[2J"; + return text.str(); + } + std::string eraseScreen() + { return "\033[2J"; } + std::string setAttr(mee::textAttributes atr){ + + } + std::string setText(mee::textColors txt){ + std::stringstream text; + text << "\033[" << static_cast(txt) << 'm'; + return text.str(); + } + std::string setBackground(mee::backColors bck){ + std::stringstream text; + text << "\033[" << static_cast(bck) << 'm'; + return text.str(); + } + std::string setColor(mee::textColors txt, mee::backColors bck){ + std::stringstream text; + text << "\033[" << static_cast(txt) << ';' << static_cast(bck) << 'm'; + return text.str(); + } + std::string setPos(unsigned int row, unsigned int col = 0){ + std::stringstream text; + text << "\033[" << row << ';' << col << 'H'; + return text.str(); + } +}; //End TermColors + +} //End namespace mee + +#endif //TERMCOLORS_HPP