mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:37:36 +00:00
LibVT/Kernel: Make VT::Attribute::Flags enum class, use AK EnumBits
Noticed the TODO in `Attribute.h` and realized we have as solution to this problem already. :^)
This commit is contained in:
parent
8601f74d5f
commit
913374163c
4 changed files with 22 additions and 22 deletions
|
@ -306,7 +306,7 @@ void VirtualConsole::flush_dirty_lines()
|
||||||
auto& cell = cell_at(column, visual_row);
|
auto& cell = cell_at(column, visual_row);
|
||||||
|
|
||||||
auto foreground_color = terminal_to_standard_color(cell.attribute.effective_foreground_color());
|
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);
|
foreground_color = (Graphics::Console::Color)((u8)foreground_color | 0x08);
|
||||||
GraphicsManagement::the().console()->write(column,
|
GraphicsManagement::the().console()->write(column,
|
||||||
visual_row,
|
visual_row,
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/EnumBits.h>
|
||||||
#include <AK/Noncopyable.h>
|
#include <AK/Noncopyable.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <LibVT/Color.h>
|
#include <LibVT/Color.h>
|
||||||
|
@ -35,15 +36,12 @@ struct Attribute {
|
||||||
Color foreground_color { default_foreground_color };
|
Color foreground_color { default_foreground_color };
|
||||||
Color background_color { default_background_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
|
#ifndef KERNEL
|
||||||
String href;
|
String href;
|
||||||
String href_id;
|
String href_id;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum Flags : u8 {
|
enum class Flags : u8 {
|
||||||
NoAttributes = 0x00,
|
NoAttributes = 0x00,
|
||||||
Bold = 0x01,
|
Bold = 0x01,
|
||||||
Italic = 0x02,
|
Italic = 0x02,
|
||||||
|
@ -52,12 +50,14 @@ struct Attribute {
|
||||||
Blink = 0x10,
|
Blink = 0x10,
|
||||||
Touched = 0x20,
|
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
|
constexpr bool is_untouched() const { return has_flag(flags, Flags::Touched); }
|
||||||
// exposed bit ops for class enums...
|
|
||||||
u8 flags { Flags::NoAttributes };
|
Flags flags { Flags::NoAttributes };
|
||||||
|
|
||||||
constexpr bool operator==(const Attribute& other) const
|
constexpr bool operator==(const Attribute& other) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -250,34 +250,34 @@ void Terminal::SGR(Parameters params)
|
||||||
m_current_state.attribute.reset();
|
m_current_state.attribute.reset();
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
m_current_state.attribute.flags |= Attribute::Bold;
|
m_current_state.attribute.flags |= Attribute::Flags::Bold;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
m_current_state.attribute.flags |= Attribute::Italic;
|
m_current_state.attribute.flags |= Attribute::Flags::Italic;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
m_current_state.attribute.flags |= Attribute::Underline;
|
m_current_state.attribute.flags |= Attribute::Flags::Underline;
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
m_current_state.attribute.flags |= Attribute::Blink;
|
m_current_state.attribute.flags |= Attribute::Flags::Blink;
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
m_current_state.attribute.flags |= Attribute::Negative;
|
m_current_state.attribute.flags |= Attribute::Flags::Negative;
|
||||||
break;
|
break;
|
||||||
case 22:
|
case 22:
|
||||||
m_current_state.attribute.flags &= ~Attribute::Bold;
|
m_current_state.attribute.flags &= ~Attribute::Flags::Bold;
|
||||||
break;
|
break;
|
||||||
case 23:
|
case 23:
|
||||||
m_current_state.attribute.flags &= ~Attribute::Italic;
|
m_current_state.attribute.flags &= ~Attribute::Flags::Italic;
|
||||||
break;
|
break;
|
||||||
case 24:
|
case 24:
|
||||||
m_current_state.attribute.flags &= ~Attribute::Underline;
|
m_current_state.attribute.flags &= ~Attribute::Flags::Underline;
|
||||||
break;
|
break;
|
||||||
case 25:
|
case 25:
|
||||||
m_current_state.attribute.flags &= ~Attribute::Blink;
|
m_current_state.attribute.flags &= ~Attribute::Flags::Blink;
|
||||||
break;
|
break;
|
||||||
case 27:
|
case 27:
|
||||||
m_current_state.attribute.flags &= ~Attribute::Negative;
|
m_current_state.attribute.flags &= ~Attribute::Flags::Negative;
|
||||||
break;
|
break;
|
||||||
case 30:
|
case 30:
|
||||||
case 31:
|
case 31:
|
||||||
|
@ -872,7 +872,7 @@ void Terminal::put_character_at(unsigned row, unsigned column, u32 code_point)
|
||||||
auto& line = active_buffer()[row];
|
auto& line = active_buffer()[row];
|
||||||
line.set_code_point(column, code_point);
|
line.set_code_point(column, code_point);
|
||||||
line.attribute_at(column) = m_current_state.attribute;
|
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);
|
line.set_dirty(true);
|
||||||
|
|
||||||
m_last_code_point = code_point;
|
m_last_code_point = code_point;
|
||||||
|
|
|
@ -342,7 +342,7 @@ void TerminalWidget::paint_event(GUI::PaintEvent& event)
|
||||||
auto underline_style = UnderlineStyle::None;
|
auto underline_style = UnderlineStyle::None;
|
||||||
auto underline_color = text_color;
|
auto underline_color = text_color;
|
||||||
|
|
||||||
if (attribute.flags & VT::Attribute::Underline) {
|
if (has_flag(attribute.flags, VT::Attribute::Flags::Underline)) {
|
||||||
// Content has specified underline
|
// Content has specified underline
|
||||||
underline_style = UnderlineStyle::Solid;
|
underline_style = UnderlineStyle::Solid;
|
||||||
} else if (!attribute.href.is_empty()) {
|
} else if (!attribute.href.is_empty()) {
|
||||||
|
@ -410,7 +410,7 @@ void TerminalWidget::paint_event(GUI::PaintEvent& event)
|
||||||
painter.draw_glyph_or_emoji(
|
painter.draw_glyph_or_emoji(
|
||||||
character_rect.location(),
|
character_rect.location(),
|
||||||
code_point,
|
code_point,
|
||||||
attribute.flags & VT::Attribute::Bold ? bold_font : font,
|
has_flag(attribute.flags, VT::Attribute::Flags::Bold) ? bold_font : font,
|
||||||
text_color);
|
text_color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue