From b57c3808e78b7d58ed2d288ea7bc5fed6eefd30b Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Wed, 28 May 2025 09:29:43 +0200 Subject: [PATCH] feat(terminal): add `BLACK` color support --- include/dwarfs/terminal.h | 4 ++++ src/terminal_ansi.cpp | 3 +++ test/test_iolayer.cpp | 3 +++ 3 files changed, 10 insertions(+) diff --git a/include/dwarfs/terminal.h b/include/dwarfs/terminal.h index 2a804c8b..da12ac93 100644 --- a/include/dwarfs/terminal.h +++ b/include/dwarfs/terminal.h @@ -36,6 +36,7 @@ namespace dwarfs { enum class termcolor { NORMAL, + BLACK, RED, GREEN, YELLOW, @@ -44,6 +45,7 @@ enum class termcolor { CYAN, WHITE, GRAY, + BOLD_BLACK, BOLD_RED, BOLD_GREEN, BOLD_YELLOW, @@ -52,6 +54,7 @@ enum class termcolor { BOLD_CYAN, BOLD_WHITE, BOLD_GRAY, + DIM_BLACK, DIM_RED, DIM_GREEN, DIM_YELLOW, @@ -74,6 +77,7 @@ class terminal { virtual bool is_fancy() const = 0; virtual std::string_view color(termcolor color, termstyle style = termstyle::NORMAL) const = 0; + virtual std::string_view bgcolor(termcolor color) const = 0; virtual std::string colored(std::string text, termcolor color, bool enable = true, termstyle style = termstyle::NORMAL) const = 0; diff --git a/src/terminal_ansi.cpp b/src/terminal_ansi.cpp index a37655af..08a1e6ee 100644 --- a/src/terminal_ansi.cpp +++ b/src/terminal_ansi.cpp @@ -140,6 +140,7 @@ std::string_view terminal_ansi::color_impl(termcolor color, termstyle style) { // clang-format off colors = {{ "\033[0m", + "\033[30m", "\033[31m", "\033[32m", "\033[33m", @@ -148,6 +149,7 @@ std::string_view terminal_ansi::color_impl(termcolor color, termstyle style) { "\033[36m", "\033[37m", "\033[90m", + "\033[1;30m", "\033[1;31m", "\033[1;32m", "\033[1;33m", @@ -156,6 +158,7 @@ std::string_view terminal_ansi::color_impl(termcolor color, termstyle style) { "\033[1;36m", "\033[1;37m", "\033[1;90m", + "\033[2;30m", "\033[2;31m", "\033[2;32m", "\033[2;33m", diff --git a/test/test_iolayer.cpp b/test/test_iolayer.cpp index 16612aed..061066a5 100644 --- a/test/test_iolayer.cpp +++ b/test/test_iolayer.cpp @@ -233,6 +233,7 @@ std::string_view test_terminal::color(termcolor color, termstyle style) const { // clang-format off colors = {{ "", + "", "", "", "", @@ -241,6 +242,7 @@ std::string_view test_terminal::color(termcolor color, termstyle style) const { "", "", "", + "", "", "", "", @@ -249,6 +251,7 @@ std::string_view test_terminal::color(termcolor color, termstyle style) const { "", "", "", + "", "", "", "",