From 7cd33b916402855e6b0ada92d00864ba73ae0142 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Tue, 24 Oct 2023 00:35:49 -0400 Subject: [PATCH] Clean up some bugs in the console color code. --- Console.cpp | 5 ++++- Console.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Console.cpp b/Console.cpp index 3940ab9..9342ef7 100644 --- a/Console.cpp +++ b/Console.cpp @@ -168,8 +168,11 @@ namespace Alepha::Hydrogen ::detail:: console const int r= boost::lexical_cast< int >( rgb.substr( 0, 1 ) ); const int g= boost::lexical_cast< int >( rgb.substr( 1, 1 ) ); const int b= boost::lexical_cast< int >( rgb.substr( 2, 1 ) ); + if( r < 0 or r > 5 ) throw std::runtime_error( "ext:rgb requested red value `" + rgb.substr( 0, 1 ) + "` out of range [0,5]" ); + if( g < 0 or g > 5 ) throw std::runtime_error( "ext:rgb requested green value `" + rgb.substr( 1, 1 ) + "` out of range [0,5]" ); + if( b < 0 or b > 5 ) throw std::runtime_error( "ext:rgb requested blue value `" + rgb.substr( 2, 1 ) + "` out of range [0,5]" ); std::ostringstream oss; - oss << "3;5;"; + oss << "38;5;"; oss << int( TextColor::rgb_base ) + r * int( TextColor::red_radix ) + g * int( TextColor::green_radix ) + b * int( TextColor::blue_radix ); return { std::move( oss ).str() }; } diff --git a/Console.h b/Console.h index 32f2755..172fce2 100644 --- a/Console.h +++ b/Console.h @@ -237,7 +237,7 @@ namespace Alepha::Hydrogen ::detail:: console rgb_base= 16, red_radix= 36, green_radix= 6, - blue_radix= 0, + blue_radix= 1, greyscale_base= 232, // Add N to this to get the greyscale offset. };