openFPGALoader/src/display.cpp

66 lines
1.3 KiB
C++
Raw Normal View History

2021-06-26 15:24:07 +02:00
// SPDX-License-Identifier: Apache-2.0
2019-11-20 07:51:21 +01:00
/*
* Copyright (C) 2019 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
*/
2020-07-11 07:56:11 +02:00
#include <unistd.h>
2019-11-20 07:51:21 +01:00
#include <iostream>
#include <string>
#include "display.hpp"
#define KNRM "\x1B[0m"
#define KRED "\x1B[31m"
#define KGRN "\x1B[32m"
#define KYEL "\x1B[33m"
#define KBLU "\x1B[34m"
2022-02-09 08:33:21 +01:00
#define KBLUL "\x1B[94m"
2019-11-20 07:51:21 +01:00
#define KMAG "\x1B[35m"
#define KCYN "\x1B[36m"
#define KWHT "\x1B[37m"
2023-04-15 08:20:05 +02:00
void printError(const std::string &err, bool eol)
2019-11-20 07:51:21 +01:00
{
2020-07-11 07:56:11 +02:00
if (isatty(STDERR_FILENO))
std::cerr << KRED << err << "\e[0m";
else
std::cerr << err;
std::cerr << std::flush;
2019-11-20 07:51:21 +01:00
if (eol)
std::cerr << std::endl;
}
2023-04-15 08:20:05 +02:00
void printWarn(const std::string &warn, bool eol)
2021-01-28 07:22:24 +01:00
{
if (isatty(STDOUT_FILENO))
std::cout << KYEL << warn << "\e[0m" << std::flush;
else
std::cout << warn;
std::cout << std::flush;
if (eol)
std::cout << std::endl;
}
2023-04-15 08:20:05 +02:00
void printInfo(const std::string &info, bool eol)
2019-11-20 07:51:21 +01:00
{
2020-07-11 07:56:11 +02:00
if (isatty(STDOUT_FILENO))
2022-02-09 08:33:21 +01:00
std::cout << KBLUL << info << "\e[0m" << std::flush;
2020-07-11 07:56:11 +02:00
else
std::cout << info;
std::cout << std::flush;
2019-11-20 07:51:21 +01:00
if (eol)
std::cout << std::endl;
}
2023-04-15 08:20:05 +02:00
void printSuccess(const std::string &success, bool eol)
2019-11-20 07:51:21 +01:00
{
2020-07-11 07:56:11 +02:00
if (isatty(STDOUT_FILENO))
std::cout << KGRN << success << "\e[0m" << std::flush;
else
std::cout << success;
std::cout << std::flush;
2019-11-20 07:51:21 +01:00
if (eol)
std::cout << std::endl;
}