-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcolor.cpp
66 lines (52 loc) · 1.34 KB
/
color.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "color.h"
#include <iostream>
using std::string;
// The following is the detailed implementation of color.h
// See "color.h" for explanation and how to use the class
// To turn respective color into partial ANSI escape code
// Input: string of a color
// Output: partial ANSI escape code of that color
string Color::generalcolor(string c){
string to_return = "";
if (c == "black")
to_return += "0m";
if (c == "red")
to_return += "1m";
if (c == "green")
to_return += "2m";
if (c == "yellow")
to_return += "3m";
if (c == "blue")
to_return += "4m";
if (c == "magenta")
to_return += "5m";
if (c == "cyan")
to_return += "6m";
if (c == "white")
to_return += "7m";
return to_return;
}
// Below are public functions
// See color.h for descriptions
void Color::set(string c, string special){
string to_return = "";
if (special == "normal")
to_return += normal;
if (special == "bright")
to_return += bright;
if (special == "background")
to_return += bground;
to_return += generalcolor(c);
std::cout << to_return;
}
void Color::reset(){
std::cout << rset;
}
string Color::setphrase(string s, string c, string brightness, string backcolor){
if (c != "normal")
set(c, brightness);
if (backcolor != "normal")
set(backcolor, "background");
return s + rset;
}
Color color;