1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:37:36 +00:00

LibLine: Add support for user-controlled masking

This commit is contained in:
Ali Mohammad Pur 2022-05-02 16:10:42 +04:30 committed by Linus Groh
parent c257d27f0b
commit 78dc77f7e4
5 changed files with 212 additions and 59 deletions

View file

@ -106,6 +106,28 @@ public:
bool m_has_link { false };
};
struct Mask {
bool operator==(Mask const& other) const
{
return other.mode == mode && other.replacement == replacement;
}
enum class Mode {
ReplaceEntireSelection,
ReplaceEachCodePointInSelection,
};
explicit Mask(StringView replacement, Mode mode = Mode::ReplaceEntireSelection)
: replacement(replacement)
, replacement_view(this->replacement)
, mode(mode)
{
}
String replacement;
mutable Utf8View replacement_view;
Mode mode;
};
static constexpr UnderlineTag Underline {};
static constexpr BoldTag Bold {};
static constexpr ItalicTag Italic {};
@ -141,6 +163,9 @@ public:
Background background() const { return m_background; }
Foreground foreground() const { return m_foreground; }
Hyperlink hyperlink() const { return m_hyperlink; }
Optional<Mask> mask() const { return m_mask; }
void unset_mask() const { m_mask = {}; }
void set(ItalicTag const&) { m_italic = true; }
void set(BoldTag const&) { m_bold = true; }
@ -149,6 +174,7 @@ public:
void set(Foreground const& fg) { m_foreground = fg; }
void set(Hyperlink const& link) { m_hyperlink = link; }
void set(AnchoredTag const&) { m_is_anchored = true; }
void set(Mask const& mask) { m_mask = mask; }
bool is_anchored() const { return m_is_anchored; }
bool is_empty() const { return m_is_empty; }
@ -162,6 +188,7 @@ private:
Background m_background { XtermColor::Unchanged };
Foreground m_foreground { XtermColor::Unchanged };
Hyperlink m_hyperlink;
mutable Optional<Mask> m_mask;
bool m_is_anchored { false };