mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-12-16 01:48:56 +08:00
Improve color handling. (#49)
This commit is contained in:
@@ -6,6 +6,18 @@
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
namespace {
|
||||
const wchar_t* palette16code[16][2] = {
|
||||
{L"30", L"40"}, {L"31", L"41"}, {L"32", L"42"}, {L"33", L"43"},
|
||||
{L"34", L"44"},
|
||||
|
||||
{L"35", L"45"}, {L"36", L"46"}, {L"37", L"47"},
|
||||
|
||||
{L"90", L"100"}, {L"91", L"101"}, {L"92", L"102"}, {L"93", L"103"},
|
||||
{L"94", L"104"}, {L"95", L"105"}, {L"96", L"106"}, {L"97", L"107"},
|
||||
};
|
||||
}
|
||||
|
||||
bool Color::operator==(const Color& rhs) const {
|
||||
return red_ == rhs.red_ && green_ == rhs.green_ && blue_ == rhs.blue_ &&
|
||||
type_ == rhs.type_;
|
||||
@@ -17,28 +29,31 @@ bool Color::operator!=(const Color& rhs) const {
|
||||
|
||||
std::wstring Color::Print(bool is_background_color) const {
|
||||
switch (type_) {
|
||||
case ColorType::Palette1:
|
||||
return is_background_color ? L"49" : L"39";
|
||||
|
||||
case ColorType::Palette16:
|
||||
return to_wstring(
|
||||
std::to_string((is_background_color ? 10 : 0) + index_));
|
||||
return palette16code[index_][is_background_color];
|
||||
|
||||
case ColorType::Palette256:
|
||||
return to_wstring(std::to_string(is_background_color ? 48 : 38) //
|
||||
+ ";5;" //
|
||||
+ std::to_string(index_)); //
|
||||
return (is_background_color ? L"48;5;" : L"38;5") + to_wstring(index_);
|
||||
|
||||
case ColorType::TrueColor:
|
||||
return to_wstring(std::to_string(is_background_color ? 48 : 38) //
|
||||
+ ";2;" //
|
||||
+ std::to_string(red_) + ";" //
|
||||
+ std::to_string(green_) + ";" //
|
||||
+ std::to_string(blue_)); //
|
||||
return (is_background_color ? L"48;2;" : L"38;2;") //
|
||||
+ to_wstring(red_) + L";" //
|
||||
+ to_wstring(green_) + L";" //
|
||||
+ to_wstring(blue_); //
|
||||
}
|
||||
return L"";
|
||||
}
|
||||
|
||||
/// @brief Build a transparent color.
|
||||
/// @ingroup screen
|
||||
Color::Color() : type_(ColorType::Palette16), index_(Palette16::Default) {}
|
||||
Color::Color() : type_(ColorType::Palette1) {}
|
||||
|
||||
/// @brief Build a transparent color.
|
||||
/// @ingroup screen
|
||||
Color::Color(Palette1) : type_(ColorType::Palette1) {}
|
||||
|
||||
/// @brief Build a transparent using Palette16 colors.
|
||||
/// @ingroup screen
|
||||
|
||||
Reference in New Issue
Block a user