From e05126e1e186dcef518c9e8b6570b1a5b4333b9c Mon Sep 17 00:00:00 2001 From: Gwenhael Goavec-Merou Date: Wed, 20 Nov 2019 07:51:21 +0100 Subject: [PATCH] display: message with color --- display.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ display.hpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 display.cpp create mode 100644 display.hpp diff --git a/display.cpp b/display.cpp new file mode 100644 index 0000000..f971bfd --- /dev/null +++ b/display.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2019 Gwenhael Goavec-Merou + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +#include "display.hpp" + +#define KNRM "\x1B[0m" +#define KRED "\x1B[31m" +#define KGRN "\x1B[32m" +#define KYEL "\x1B[33m" +#define KBLU "\x1B[34m" +#define KMAG "\x1B[35m" +#define KCYN "\x1B[36m" +#define KWHT "\x1B[37m" + +void printError(std::string err, bool eol) +{ + std::cerr << KRED << err << "\e[0m" << std::flush; + if (eol) + std::cerr << std::endl; +} + +void printInfo(std::string info, bool eol) +{ + std::cout << KBLU << info << "\e[0m" << std::flush; + if (eol) + std::cout << std::endl; +} + +void printSuccess(std::string success, bool eol) +{ + std::cout << KGRN << success << "\e[0m" << std::flush; + if (eol) + std::cout << std::endl; +} diff --git a/display.hpp b/display.hpp new file mode 100644 index 0000000..3e82fe5 --- /dev/null +++ b/display.hpp @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2019 Gwenhael Goavec-Merou + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef DISPLAY_HPP_ +#define DISPLAY_HPP_ + +#include +#include + +void printError(std::string err, bool eol = true); +void printInfo(std::string info, bool eol = true); +void printSuccess(std::string success, bool eol = true); + +#endif // DISPLAY_HPP_