Attribute.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/EnumBits.h>
  8. #include <AK/Noncopyable.h>
  9. #include <AK/Vector.h>
  10. #include <LibVT/Color.h>
  11. #include <LibVT/XtermColors.h>
  12. #ifndef KERNEL
  13. # include <AK/ByteString.h>
  14. #endif
  15. namespace VT {
  16. struct Attribute {
  17. static constexpr Color default_foreground_color = Color::named(Color::ANSIColor::DefaultForeground);
  18. static constexpr Color default_background_color = Color::named(Color::ANSIColor::DefaultBackground);
  19. void reset()
  20. {
  21. foreground_color = default_foreground_color;
  22. background_color = default_background_color;
  23. flags = Flags::NoAttributes;
  24. #ifndef KERNEL
  25. href = {};
  26. href_id = {};
  27. #endif
  28. }
  29. Color foreground_color { default_foreground_color };
  30. Color background_color { default_background_color };
  31. #ifndef KERNEL
  32. ByteString href;
  33. Optional<ByteString> href_id;
  34. #endif
  35. enum class Flags : u8 {
  36. NoAttributes = 0x00,
  37. Bold = 0x01,
  38. Italic = 0x02,
  39. Underline = 0x04,
  40. Negative = 0x08,
  41. Blink = 0x10,
  42. Touched = 0x20,
  43. };
  44. AK_ENUM_BITWISE_FRIEND_OPERATORS(Flags);
  45. constexpr Color effective_background_color() const { return has_flag(flags, Flags::Negative) ? foreground_color : background_color; }
  46. constexpr Color effective_foreground_color() const { return has_flag(flags, Flags::Negative) ? background_color : foreground_color; }
  47. constexpr bool is_untouched() const { return !has_flag(flags, Flags::Touched); }
  48. Flags flags { Flags::NoAttributes };
  49. constexpr bool operator==(Attribute const& other) const
  50. {
  51. return foreground_color == other.foreground_color && background_color == other.background_color && flags == other.flags;
  52. }
  53. };
  54. }