1
0
Fork 0
mirror of https://github.com/eosswedenorg/antelope-keygen synced 2026-06-18 04:00:03 +02:00

console: add disable_color flag.

This commit is contained in:
Henrik Hautakoski 2020-02-18 14:29:53 +01:00
parent 7bae67ddbc
commit f1f9eb5a66
5 changed files with 68 additions and 23 deletions

View file

@ -17,6 +17,7 @@ include(GNUInstallDirs)
set (PROGRAM_EXE ${CMAKE_PROJECT_NAME})
set (PROGRAM_SOURCE
src/console.cpp
src/string.cpp
src/base58.cpp
src/WIF.cpp

30
src/console.cpp Normal file
View file

@ -0,0 +1,30 @@
/**
* MIT License
*
* Copyright (c) 2019-2020 EOS Sw/eden
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "console.h"
namespace eoskeygen { namespace console {
bool disable_color = false;
} } // namespace eoskeygen::console

View file

@ -30,6 +30,8 @@ namespace eoskeygen {
namespace console {
extern bool disable_color;
// enum for all supported colors.
enum Color {
default_fg,

View file

@ -29,6 +29,10 @@ namespace eoskeygen {
namespace console {
std::ostream& reset(std::ostream& os) {
if (disable_color) {
return os;
}
return os << "\033[0m";
}
@ -38,6 +42,10 @@ std::ostream& operator<<(std::ostream& os, const fg& obj) {
int attr;
int code;
if (disable_color) {
return os;
}
switch(obj._color) {
case black : code = 30; break;
case red : code = 31; break;

View file

@ -50,8 +50,9 @@ namespace console {
std::ostream& reset(std::ostream& os) {
::SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE), FG_DEFAULT);
if (disable_color == false) {
::SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE), FG_DEFAULT);
}
return os;
}
@ -60,28 +61,31 @@ std::ostream& operator<<(std::ostream& os, const fg& obj) {
int code;
switch(obj._color) {
case black : code = FG_BLACK; break;
case red : code = FG_RED; break;
case green : code = FG_GREEN; break;
case blue : code = FG_BLUE; break;
case yellow : code = FG_YELLOW; break;
case magenta : code = FG_MAGENTA; break;
case cyan : code = FG_CYAN; break;
case light_grey : code = FG_GREY; break;
case light_red : code = FG_LIGHTRED; break;
case light_green : code = FG_LIGHTGREEN; break;
case light_yellow : code = FG_LIGHTYELLOW; break;
case light_blue : code = FG_LIGHTBLUE; break;
case light_magenta : code = FG_LIGHTMAGENTA; break;
case light_cyan : code = FG_LIGHTCYAN; break;
case dark_grey : code = FG_DARKGREY; break;
case white : code = FG_WHITE; break;
case default_fg : default :
code = FG_DEFAULT;
}
if (disable_color == false) {
::SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE), code);
switch(obj._color) {
case black : code = FG_BLACK; break;
case red : code = FG_RED; break;
case green : code = FG_GREEN; break;
case blue : code = FG_BLUE; break;
case yellow : code = FG_YELLOW; break;
case magenta : code = FG_MAGENTA; break;
case cyan : code = FG_CYAN; break;
case light_grey : code = FG_GREY; break;
case light_red : code = FG_LIGHTRED; break;
case light_green : code = FG_LIGHTGREEN; break;
case light_yellow : code = FG_LIGHTYELLOW; break;
case light_blue : code = FG_LIGHTBLUE; break;
case light_magenta : code = FG_LIGHTMAGENTA; break;
case light_cyan : code = FG_LIGHTCYAN; break;
case dark_grey : code = FG_DARKGREY; break;
case white : code = FG_WHITE; break;
case default_fg : default :
code = FG_DEFAULT;
}
::SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE), code);
}
// WinAPI does not support text attributes in the console.
// so we ignore those.