mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 10:17:35 +00:00
LibVT: Move out the Line class from Terminal to its own class
This commit is contained in:
parent
345fbd1fc1
commit
16965db86b
6 changed files with 232 additions and 149 deletions
|
@ -30,14 +30,14 @@
|
|||
#include <AK/NonnullOwnPtrVector.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibVT/Line.h>
|
||||
#include <LibVT/Position.h>
|
||||
#include <LibVT/XtermColors.h>
|
||||
|
||||
namespace VT {
|
||||
|
||||
class TerminalClient {
|
||||
public:
|
||||
virtual ~TerminalClient() {}
|
||||
virtual ~TerminalClient() { }
|
||||
|
||||
virtual void beep() = 0;
|
||||
virtual void set_window_title(const StringView&) = 0;
|
||||
|
@ -46,50 +46,6 @@ public:
|
|||
virtual void emit(const u8*, size_t) = 0;
|
||||
};
|
||||
|
||||
struct Attribute {
|
||||
Attribute() { reset(); }
|
||||
|
||||
static const u32 default_foreground_color = xterm_colors[7];
|
||||
static const u32 default_background_color = xterm_colors[0];
|
||||
|
||||
void reset()
|
||||
{
|
||||
foreground_color = default_foreground_color;
|
||||
background_color = default_background_color;
|
||||
flags = Flags::NoAttributes;
|
||||
}
|
||||
u32 foreground_color;
|
||||
u32 background_color;
|
||||
|
||||
String href;
|
||||
String href_id;
|
||||
|
||||
enum Flags : u8 {
|
||||
NoAttributes = 0x00,
|
||||
Bold = 0x01,
|
||||
Italic = 0x02,
|
||||
Underline = 0x04,
|
||||
Negative = 0x08,
|
||||
Blink = 0x10,
|
||||
Touched = 0x20,
|
||||
};
|
||||
|
||||
bool is_untouched() const { return !(flags & Touched); }
|
||||
|
||||
// TODO: it would be really nice if we had a helper for enums that
|
||||
// exposed bit ops for class enums...
|
||||
u8 flags = Flags::NoAttributes;
|
||||
|
||||
bool operator==(const Attribute& other) const
|
||||
{
|
||||
return foreground_color == other.foreground_color && background_color == other.background_color && flags == other.flags;
|
||||
}
|
||||
bool operator!=(const Attribute& other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
};
|
||||
|
||||
class Terminal {
|
||||
public:
|
||||
explicit Terminal(TerminalClient&);
|
||||
|
@ -108,24 +64,6 @@ public:
|
|||
u16 cursor_column() const { return m_cursor_column; }
|
||||
u16 cursor_row() const { return m_cursor_row; }
|
||||
|
||||
struct Line {
|
||||
AK_MAKE_NONCOPYABLE(Line);
|
||||
AK_MAKE_NONMOVABLE(Line);
|
||||
|
||||
public:
|
||||
explicit Line(u16 columns);
|
||||
~Line();
|
||||
void clear(Attribute);
|
||||
bool has_only_one_background_color() const;
|
||||
void set_length(u16);
|
||||
StringView text() const { return { characters, m_length }; }
|
||||
|
||||
u8* characters { nullptr };
|
||||
Attribute* attributes { nullptr };
|
||||
bool dirty { false };
|
||||
u16 m_length { 0 };
|
||||
};
|
||||
|
||||
size_t line_count() const
|
||||
{
|
||||
return m_history.size() + m_lines.size();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue