Skip to content

Commit

Permalink
Add equality ops to for Color and Brush
Browse files Browse the repository at this point in the history
  • Loading branch information
a-n-t-h-o-n-y committed Jan 19, 2024
1 parent e92030d commit dfba02f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
15 changes: 15 additions & 0 deletions include/esc/brush.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,20 @@ struct Brush {
Traits traits = Traits{Trait::None};
};

/// Returns true if the two Brushes have the same background, foreground, and
/// traits.
[[nodiscard]] inline auto operator==(Brush const& lhs, Brush const& rhs) -> bool
{
return lhs.background == rhs.background &&
lhs.foreground == rhs.foreground && lhs.traits == rhs.traits;
}

/// Returns true if the two Brushes do not have the same background, foreground,
/// and traits.
[[nodiscard]] inline auto operator!=(Brush const& lhs, Brush const& rhs) -> bool
{
return !(lhs == rhs);
}

} // namespace esc
#endif // ESC_BRUSH_HPP
12 changes: 12 additions & 0 deletions include/esc/default_color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ namespace esc {
/// Default Color of the terminal.
struct Default_color {};

/// Checks for equality, always returns true.
[[nodiscard]] constexpr auto operator==(Default_color, Default_color) -> bool
{
return true;
}

/// Checks for inequality, always returns false.
[[nodiscard]] constexpr auto operator!=(Default_color, Default_color) -> bool
{
return false;
}

/// Tag type for terminal default color background.
struct BG_Default_color {};

Expand Down
14 changes: 14 additions & 0 deletions include/esc/true_color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ class True_color {
constexpr True_color(HSL x) : True_color{hsl_to_rgb(x)} {}
};

/// Returns true if the two True_colors are the same.
[[nodiscard]] inline auto operator==(True_color const& lhs,
True_color const& rhs) -> bool
{
return lhs.red == rhs.red && lhs.green == rhs.green && lhs.blue == rhs.blue;
}

/// Returns true if the two True_colors are not the same.
[[nodiscard]] inline auto operator!=(True_color const& lhs,
True_color const& rhs) -> bool
{
return !(lhs == rhs);
}

/// Tag type for True_color that is used as a background.
struct BG_True_color {
True_color value;
Expand Down

0 comments on commit dfba02f

Please sign in to comment.