1 // SPDX-License-Identifier: Apache-2.0
2 /*
3  * Copyright (C) 2019 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
4  */
5 
6 #include <unistd.h>
7 
8 #include <iostream>
9 #include <string>
10 
11 #include "display.hpp"
12 
13 #define KNRM  "\x1B[0m"
14 #define KRED  "\x1B[31m"
15 #define KGRN  "\x1B[32m"
16 #define KYEL  "\x1B[33m"
17 #define KBLU  "\x1B[34m"
18 #define KMAG  "\x1B[35m"
19 #define KCYN  "\x1B[36m"
20 #define KWHT  "\x1B[37m"
21 
printError(std::string err,bool eol)22 void printError(std::string err, bool eol)
23 {
24 	if (isatty(STDERR_FILENO))
25 		std::cerr << KRED << err << "\e[0m";
26 	else
27 		std::cerr << err;
28 	std::cerr << std::flush;
29 	if (eol)
30 		std::cerr << std::endl;
31 }
32 
printWarn(std::string warn,bool eol)33 void printWarn(std::string warn, bool eol)
34 {
35 	if (isatty(STDOUT_FILENO))
36 		std::cout << KYEL << warn << "\e[0m" << std::flush;
37 	else
38 		std::cout << warn;
39 	std::cout << std::flush;
40 	if (eol)
41 		std::cout << std::endl;
42 }
43 
printInfo(std::string info,bool eol)44 void printInfo(std::string info, bool eol)
45 {
46 	if (isatty(STDOUT_FILENO))
47 		std::cout << KBLU << info << "\e[0m" << std::flush;
48 	else
49 		std::cout << info;
50 	std::cout << std::flush;
51 	if (eol)
52 		std::cout << std::endl;
53 }
54 
printSuccess(std::string success,bool eol)55 void printSuccess(std::string success, bool eol)
56 {
57 	if (isatty(STDOUT_FILENO))
58 		std::cout << KGRN << success << "\e[0m" << std::flush;
59 	else
60 		std::cout << success;
61 	std::cout << std::flush;
62 	if (eol)
63 		std::cout << std::endl;
64 }
65