Leosac  0.8.0
Open Source Access Control
Colorize.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include <sstream>
23 #include <string>
24 
25 namespace Leosac
26 {
30 namespace Colorize
31 {
37 namespace detail
38 {
39 static std::string clear()
40 {
41  return "\033[0m";
42 }
43 
48 template <typename T>
49 std::string format(const std::string &escape_code, const T &in)
50 {
51  std::stringstream ss;
52  ss << "\033[" << escape_code << "m" << in << clear();
53  return ss.str();
54 }
55 }
56 
57 template <typename T>
58 std::string bold(const T &in)
59 {
60  return detail::format("1", in);
61 }
62 
63 template <typename T>
64 std::string underline(const T &in)
65 {
66  return detail::format("4", in);
67 }
68 
69 template <typename T>
70 std::string red(const T &in)
71 {
72  return detail::format("31", in);
73 }
74 
75 template <typename T>
76 std::string bright_red(const T &in)
77 {
78  return detail::format("31;1", in);
79 }
80 
81 template <typename T>
82 std::string green(const T &in)
83 {
84  return detail::format("32", in);
85 }
86 
87 template <typename T>
88 std::string bright_green(const T &in)
89 {
90  return detail::format("32;2", in);
91 }
92 
93 template <typename T>
94 std::string cyan(const T &in)
95 {
96  return detail::format("36", in);
97 }
98 
99 template <typename T>
100 std::string bright_cyan(const T &in)
101 {
102  return detail::format("36;6", in);
103 }
104 }
105 }
Leosac::Colorize::underline
std::string underline(const T &in)
Definition: Colorize.hpp:64
Leosac::Colorize::bright_cyan
std::string bright_cyan(const T &in)
Definition: Colorize.hpp:100
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Colorize::bright_green
std::string bright_green(const T &in)
Definition: Colorize.hpp:88
Leosac::Colorize::bold
std::string bold(const T &in)
Definition: Colorize.hpp:58
Leosac::Colorize::green
std::string green(const T &in)
Definition: Colorize.hpp:82
Leosac::Colorize::red
std::string red(const T &in)
Definition: Colorize.hpp:70
Leosac::Colorize::bright_red
std::string bright_red(const T &in)
Definition: Colorize.hpp:76
Leosac::Colorize::detail::format
std::string format(const std::string &escape_code, const T &in)
Return a string containing the escape code, a string representation of T and the clear escape string.
Definition: Colorize.hpp:49
Leosac::Colorize::cyan
std::string cyan(const T &in)
Definition: Colorize.hpp:94