1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 14:37:45 +00:00

LibVT+Kernel: Create Color class

Previously, we converted colors to their RGB values immediately when
they were set. This meant that their semantic meaning was lost, we could
not tell a precise RGB value apart from a named/indexed color.

The new way of storing colors will allow us to retain this information,
so we can change a color scheme on the fly, and previously emitted text
will also be affected.
This commit is contained in:
Daniel Bertalan 2021-05-27 19:19:30 +02:00 committed by Linus Groh
parent 054c742d17
commit 99033876ec
7 changed files with 232 additions and 80 deletions

View file

@ -9,6 +9,7 @@
#include <AK/Noncopyable.h>
#include <AK/String.h>
#include <AK/Vector.h>
#include <LibVT/Color.h>
#include <LibVT/XtermColors.h>
namespace VT {
@ -16,8 +17,8 @@ namespace VT {
struct Attribute {
Attribute() { reset(); }
static const u32 default_foreground_color = xterm_colors[7];
static const u32 default_background_color = xterm_colors[0];
static constexpr Color default_foreground_color = Color::named(Color::ANSIColor::DefaultForeground);
static constexpr Color default_background_color = Color::named(Color::ANSIColor::DefaultBackground);
void reset()
{
@ -25,11 +26,11 @@ struct Attribute {
background_color = default_background_color;
flags = Flags::NoAttributes;
}
u32 foreground_color {};
u32 background_color {};
Color foreground_color { default_foreground_color };
Color background_color { default_background_color };
u32 effective_background_color() const { return flags & Negative ? foreground_color : background_color; }
u32 effective_foreground_color() const { return flags & Negative ? background_color : foreground_color; }
Color effective_background_color() const { return flags & Negative ? foreground_color : background_color; }
Color effective_foreground_color() const { return flags & Negative ? background_color : foreground_color; }
#ifndef KERNEL
String href;