2021-04-16 22:58:51 +03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2022-03-17 23:14:50 -07:00
|
|
|
#include <AK/EnumBits.h>
|
2021-04-16 22:58:51 +03:00
|
|
|
#include <AK/Noncopyable.h>
|
|
|
|
|
#include <AK/Vector.h>
|
2021-05-27 19:19:30 +02:00
|
|
|
#include <LibVT/Color.h>
|
2021-04-16 22:58:51 +03:00
|
|
|
#include <LibVT/XtermColors.h>
|
|
|
|
|
|
2022-02-15 22:46:49 +02:00
|
|
|
#ifndef KERNEL
|
2023-12-16 17:49:34 +03:30
|
|
|
# include <AK/ByteString.h>
|
2022-02-15 22:46:49 +02:00
|
|
|
#endif
|
|
|
|
|
|
2021-04-16 22:58:51 +03:00
|
|
|
namespace VT {
|
|
|
|
|
|
|
|
|
|
struct Attribute {
|
2021-05-27 19:19:30 +02:00
|
|
|
static constexpr Color default_foreground_color = Color::named(Color::ANSIColor::DefaultForeground);
|
|
|
|
|
static constexpr Color default_background_color = Color::named(Color::ANSIColor::DefaultBackground);
|
2021-04-16 22:58:51 +03:00
|
|
|
|
|
|
|
|
void reset()
|
|
|
|
|
{
|
|
|
|
|
foreground_color = default_foreground_color;
|
|
|
|
|
background_color = default_background_color;
|
|
|
|
|
flags = Flags::NoAttributes;
|
2021-06-05 11:12:00 +02:00
|
|
|
#ifndef KERNEL
|
|
|
|
|
href = {};
|
|
|
|
|
href_id = {};
|
|
|
|
|
#endif
|
2021-04-16 22:58:51 +03:00
|
|
|
}
|
2021-06-05 11:12:00 +02:00
|
|
|
|
2021-05-27 19:19:30 +02:00
|
|
|
Color foreground_color { default_foreground_color };
|
|
|
|
|
Color background_color { default_background_color };
|
2021-04-16 22:58:51 +03:00
|
|
|
|
|
|
|
|
#ifndef KERNEL
|
2023-12-16 17:49:34 +03:30
|
|
|
ByteString href;
|
|
|
|
|
Optional<ByteString> href_id;
|
2021-04-16 22:58:51 +03:00
|
|
|
#endif
|
|
|
|
|
|
2022-03-17 23:14:50 -07:00
|
|
|
enum class Flags : u8 {
|
2021-04-16 22:58:51 +03:00
|
|
|
NoAttributes = 0x00,
|
|
|
|
|
Bold = 0x01,
|
|
|
|
|
Italic = 0x02,
|
|
|
|
|
Underline = 0x04,
|
|
|
|
|
Negative = 0x08,
|
|
|
|
|
Blink = 0x10,
|
|
|
|
|
Touched = 0x20,
|
|
|
|
|
};
|
2022-03-17 23:14:50 -07:00
|
|
|
AK_ENUM_BITWISE_FRIEND_OPERATORS(Flags);
|
|
|
|
|
|
|
|
|
|
constexpr Color effective_background_color() const { return has_flag(flags, Flags::Negative) ? foreground_color : background_color; }
|
|
|
|
|
constexpr Color effective_foreground_color() const { return has_flag(flags, Flags::Negative) ? background_color : foreground_color; }
|
2021-04-16 22:58:51 +03:00
|
|
|
|
2022-03-20 12:46:05 -07:00
|
|
|
constexpr bool is_untouched() const { return !has_flag(flags, Flags::Touched); }
|
2021-04-16 22:58:51 +03:00
|
|
|
|
2022-03-17 23:14:50 -07:00
|
|
|
Flags flags { Flags::NoAttributes };
|
2021-04-16 22:58:51 +03:00
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
constexpr bool operator==(Attribute const& other) const
|
2021-04-16 22:58:51 +03:00
|
|
|
{
|
|
|
|
|
return foreground_color == other.foreground_color && background_color == other.background_color && flags == other.flags;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|