diff --git a/Kernel/TTY/VirtualConsole.cpp b/Kernel/TTY/VirtualConsole.cpp index e6470d48d95..151783bbd38 100644 --- a/Kernel/TTY/VirtualConsole.cpp +++ b/Kernel/TTY/VirtualConsole.cpp @@ -306,7 +306,7 @@ void VirtualConsole::flush_dirty_lines() auto& cell = cell_at(column, visual_row); auto foreground_color = terminal_to_standard_color(cell.attribute.effective_foreground_color()); - if (cell.attribute.flags & VT::Attribute::Flags::Bold) + if (has_flag(cell.attribute.flags, VT::Attribute::Flags::Bold)) foreground_color = (Graphics::Console::Color)((u8)foreground_color | 0x08); GraphicsManagement::the().console()->write(column, visual_row, diff --git a/Userland/Libraries/LibVT/Attribute.h b/Userland/Libraries/LibVT/Attribute.h index 5bc71531fe9..684a403b3a7 100644 --- a/Userland/Libraries/LibVT/Attribute.h +++ b/Userland/Libraries/LibVT/Attribute.h @@ -6,6 +6,7 @@ #pragma once +#include #include #include #include @@ -35,15 +36,12 @@ struct Attribute { Color foreground_color { default_foreground_color }; Color background_color { default_background_color }; - constexpr Color effective_background_color() const { return flags & Negative ? foreground_color : background_color; } - constexpr Color effective_foreground_color() const { return flags & Negative ? background_color : foreground_color; } - #ifndef KERNEL String href; String href_id; #endif - enum Flags : u8 { + enum class Flags : u8 { NoAttributes = 0x00, Bold = 0x01, Italic = 0x02, @@ -52,12 +50,14 @@ struct Attribute { Blink = 0x10, Touched = 0x20, }; + AK_ENUM_BITWISE_FRIEND_OPERATORS(Flags); - constexpr bool is_untouched() const { return !(flags & Touched); } + 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; } - // TODO: it would be really nice if we had a helper for enums that - // exposed bit ops for class enums... - u8 flags { Flags::NoAttributes }; + constexpr bool is_untouched() const { return has_flag(flags, Flags::Touched); } + + Flags flags { Flags::NoAttributes }; constexpr bool operator==(const Attribute& other) const { diff --git a/Userland/Libraries/LibVT/Terminal.cpp b/Userland/Libraries/LibVT/Terminal.cpp index f5f0d96f140..7e669a5f40e 100644 --- a/Userland/Libraries/LibVT/Terminal.cpp +++ b/Userland/Libraries/LibVT/Terminal.cpp @@ -250,34 +250,34 @@ void Terminal::SGR(Parameters params) m_current_state.attribute.reset(); break; case 1: - m_current_state.attribute.flags |= Attribute::Bold; + m_current_state.attribute.flags |= Attribute::Flags::Bold; break; case 3: - m_current_state.attribute.flags |= Attribute::Italic; + m_current_state.attribute.flags |= Attribute::Flags::Italic; break; case 4: - m_current_state.attribute.flags |= Attribute::Underline; + m_current_state.attribute.flags |= Attribute::Flags::Underline; break; case 5: - m_current_state.attribute.flags |= Attribute::Blink; + m_current_state.attribute.flags |= Attribute::Flags::Blink; break; case 7: - m_current_state.attribute.flags |= Attribute::Negative; + m_current_state.attribute.flags |= Attribute::Flags::Negative; break; case 22: - m_current_state.attribute.flags &= ~Attribute::Bold; + m_current_state.attribute.flags &= ~Attribute::Flags::Bold; break; case 23: - m_current_state.attribute.flags &= ~Attribute::Italic; + m_current_state.attribute.flags &= ~Attribute::Flags::Italic; break; case 24: - m_current_state.attribute.flags &= ~Attribute::Underline; + m_current_state.attribute.flags &= ~Attribute::Flags::Underline; break; case 25: - m_current_state.attribute.flags &= ~Attribute::Blink; + m_current_state.attribute.flags &= ~Attribute::Flags::Blink; break; case 27: - m_current_state.attribute.flags &= ~Attribute::Negative; + m_current_state.attribute.flags &= ~Attribute::Flags::Negative; break; case 30: case 31: @@ -872,7 +872,7 @@ void Terminal::put_character_at(unsigned row, unsigned column, u32 code_point) auto& line = active_buffer()[row]; line.set_code_point(column, code_point); line.attribute_at(column) = m_current_state.attribute; - line.attribute_at(column).flags |= Attribute::Touched; + line.attribute_at(column).flags |= Attribute::Flags::Touched; line.set_dirty(true); m_last_code_point = code_point; diff --git a/Userland/Libraries/LibVT/TerminalWidget.cpp b/Userland/Libraries/LibVT/TerminalWidget.cpp index a2bbb05a97d..714b872c448 100644 --- a/Userland/Libraries/LibVT/TerminalWidget.cpp +++ b/Userland/Libraries/LibVT/TerminalWidget.cpp @@ -342,7 +342,7 @@ void TerminalWidget::paint_event(GUI::PaintEvent& event) auto underline_style = UnderlineStyle::None; auto underline_color = text_color; - if (attribute.flags & VT::Attribute::Underline) { + if (has_flag(attribute.flags, VT::Attribute::Flags::Underline)) { // Content has specified underline underline_style = UnderlineStyle::Solid; } else if (!attribute.href.is_empty()) { @@ -410,7 +410,7 @@ void TerminalWidget::paint_event(GUI::PaintEvent& event) painter.draw_glyph_or_emoji( character_rect.location(), code_point, - attribute.flags & VT::Attribute::Bold ? bold_font : font, + has_flag(attribute.flags, VT::Attribute::Flags::Bold) ? bold_font : font, text_color); } }