2019-01-15 04:30:55 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/AKString.h>
|
|
|
|
|
#include <AK/Types.h>
|
|
|
|
|
#include <AK/Vector.h>
|
2019-05-28 11:53:16 +02:00
|
|
|
#include <LibCore/CConfigFile.h>
|
2019-04-10 17:35:43 +02:00
|
|
|
#include <LibCore/CNotifier.h>
|
2019-04-12 00:09:45 +02:00
|
|
|
#include <LibCore/CTimer.h>
|
2019-05-28 11:53:16 +02:00
|
|
|
#include <LibGUI/GFrame.h>
|
2019-07-18 10:15:00 +02:00
|
|
|
#include <LibDraw/GraphicsBitmap.h>
|
|
|
|
|
#include <LibDraw/Rect.h>
|
2019-01-15 04:30:55 +01:00
|
|
|
|
2019-01-17 16:19:49 +01:00
|
|
|
class Font;
|
2019-01-15 04:30:55 +01:00
|
|
|
|
2019-06-23 09:18:17 +02:00
|
|
|
class BufferPosition {
|
|
|
|
|
public:
|
|
|
|
|
BufferPosition() {}
|
|
|
|
|
BufferPosition(int row, int column)
|
|
|
|
|
: m_row(row)
|
|
|
|
|
, m_column(column)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_valid() const { return m_row >= 0 && m_column >= 0; }
|
|
|
|
|
int row() const { return m_row; }
|
|
|
|
|
int column() const { return m_column; }
|
|
|
|
|
|
|
|
|
|
bool operator<(const BufferPosition& other) const
|
|
|
|
|
{
|
|
|
|
|
return m_row < other.m_row || (m_row == other.m_row && m_column < other.m_column);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool operator<=(const BufferPosition& other) const
|
|
|
|
|
{
|
|
|
|
|
return *this < other || *this == other;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool operator>=(const BufferPosition& other) const
|
|
|
|
|
{
|
|
|
|
|
return !(*this < other);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool operator==(const BufferPosition& other) const
|
|
|
|
|
{
|
|
|
|
|
return m_row == other.m_row && m_column == other.m_column;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool operator!=(const BufferPosition& other) const
|
|
|
|
|
{
|
|
|
|
|
return !(*this == other);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
int m_row { -1 };
|
|
|
|
|
int m_column { -1 };
|
|
|
|
|
};
|
|
|
|
|
|
2019-05-11 02:27:06 +02:00
|
|
|
class Terminal final : public GFrame {
|
2019-01-15 04:30:55 +01:00
|
|
|
public:
|
2019-06-21 18:37:47 +02:00
|
|
|
explicit Terminal(int ptm_fd, RefPtr<CConfigFile> config);
|
2019-02-10 14:28:39 +01:00
|
|
|
virtual ~Terminal() override;
|
2019-01-15 04:30:55 +01:00
|
|
|
|
|
|
|
|
void create_window();
|
2019-07-03 21:17:35 +02:00
|
|
|
void on_char(u8);
|
2019-01-15 04:30:55 +01:00
|
|
|
|
2019-02-10 14:28:39 +01:00
|
|
|
void flush_dirty_lines();
|
2019-02-12 10:08:35 +01:00
|
|
|
void force_repaint();
|
2019-01-17 17:38:04 +01:00
|
|
|
|
2019-02-21 00:21:23 +01:00
|
|
|
void apply_size_increments_to_window(GWindow&);
|
|
|
|
|
|
2019-07-03 21:17:35 +02:00
|
|
|
void set_opacity(u8);
|
2019-05-31 13:28:47 -07:00
|
|
|
float opacity() { return m_opacity; };
|
|
|
|
|
bool should_beep() { return m_should_beep; }
|
2019-05-31 12:43:58 -07:00
|
|
|
void set_should_beep(bool sb) { m_should_beep = sb; };
|
2019-04-29 19:24:18 +02:00
|
|
|
|
2019-06-21 18:37:47 +02:00
|
|
|
RefPtr<CConfigFile> config() const { return m_config; }
|
2019-05-25 16:43:15 -07:00
|
|
|
|
2019-06-23 09:18:17 +02:00
|
|
|
bool has_selection() const;
|
|
|
|
|
bool selection_contains(const BufferPosition&) const;
|
|
|
|
|
String selected_text() const;
|
|
|
|
|
BufferPosition buffer_position_at(const Point&) const;
|
|
|
|
|
BufferPosition normalized_selection_start() const;
|
|
|
|
|
BufferPosition normalized_selection_end() const;
|
|
|
|
|
|
2019-01-15 04:30:55 +01:00
|
|
|
private:
|
2019-04-20 14:02:19 +02:00
|
|
|
typedef Vector<unsigned, 4> ParamVector;
|
|
|
|
|
|
2019-04-10 16:56:55 +02:00
|
|
|
virtual void event(CEvent&) override;
|
2019-02-10 14:28:39 +01:00
|
|
|
virtual void paint_event(GPaintEvent&) override;
|
2019-02-20 21:59:13 +01:00
|
|
|
virtual void resize_event(GResizeEvent&) override;
|
2019-02-10 14:28:39 +01:00
|
|
|
virtual void keydown_event(GKeyEvent&) override;
|
2019-06-23 09:18:17 +02:00
|
|
|
virtual void mousedown_event(GMouseEvent&) override;
|
|
|
|
|
virtual void mousemove_event(GMouseEvent&) override;
|
|
|
|
|
virtual void mouseup_event(GMouseEvent&) override;
|
2019-02-10 14:28:39 +01:00
|
|
|
virtual const char* class_name() const override { return "Terminal"; }
|
|
|
|
|
|
2019-01-15 04:30:55 +01:00
|
|
|
void scroll_up();
|
2019-05-28 15:40:44 -07:00
|
|
|
void scroll_down();
|
2019-02-03 14:00:48 +01:00
|
|
|
void newline();
|
2019-01-15 04:30:55 +01:00
|
|
|
void set_cursor(unsigned row, unsigned column);
|
2019-07-03 21:17:35 +02:00
|
|
|
void put_character_at(unsigned row, unsigned column, u8 ch);
|
2019-01-17 17:38:04 +01:00
|
|
|
void invalidate_cursor();
|
2019-05-12 14:57:15 +02:00
|
|
|
void set_window_title(const String&);
|
2019-01-15 04:30:55 +01:00
|
|
|
|
2019-01-30 21:04:49 +01:00
|
|
|
void inject_string(const String&);
|
|
|
|
|
void unimplemented_escape();
|
|
|
|
|
void unimplemented_xterm_escape();
|
|
|
|
|
|
2019-04-20 14:02:19 +02:00
|
|
|
void escape$A(const ParamVector&);
|
|
|
|
|
void escape$B(const ParamVector&);
|
|
|
|
|
void escape$C(const ParamVector&);
|
|
|
|
|
void escape$D(const ParamVector&);
|
|
|
|
|
void escape$H(const ParamVector&);
|
|
|
|
|
void escape$J(const ParamVector&);
|
|
|
|
|
void escape$K(const ParamVector&);
|
|
|
|
|
void escape$M(const ParamVector&);
|
2019-06-12 20:53:50 +02:00
|
|
|
void escape$P(const ParamVector&);
|
2019-04-20 14:02:19 +02:00
|
|
|
void escape$G(const ParamVector&);
|
|
|
|
|
void escape$X(const ParamVector&);
|
2019-06-11 07:31:47 +02:00
|
|
|
void escape$b(const ParamVector&);
|
2019-04-20 14:02:19 +02:00
|
|
|
void escape$d(const ParamVector&);
|
|
|
|
|
void escape$m(const ParamVector&);
|
|
|
|
|
void escape$s(const ParamVector&);
|
|
|
|
|
void escape$u(const ParamVector&);
|
|
|
|
|
void escape$t(const ParamVector&);
|
|
|
|
|
void escape$r(const ParamVector&);
|
2019-05-28 15:40:44 -07:00
|
|
|
void escape$S(const ParamVector&);
|
|
|
|
|
void escape$T(const ParamVector&);
|
|
|
|
|
void escape$L(const ParamVector&);
|
2019-05-29 10:53:21 -07:00
|
|
|
void escape$h_l(bool, bool, const ParamVector&);
|
2019-01-15 04:30:55 +01:00
|
|
|
|
|
|
|
|
void clear();
|
|
|
|
|
|
2019-07-03 21:17:35 +02:00
|
|
|
void set_size(u16 columns, u16 rows);
|
|
|
|
|
u16 columns() const { return m_columns; }
|
|
|
|
|
u16 rows() const { return m_rows; }
|
|
|
|
|
Rect glyph_rect(u16 row, u16 column);
|
|
|
|
|
Rect row_rect(u16 row);
|
2019-03-30 21:40:27 +01:00
|
|
|
void update_cursor();
|
2019-01-15 04:30:55 +01:00
|
|
|
|
2019-01-15 07:30:24 +01:00
|
|
|
struct Attribute {
|
|
|
|
|
Attribute() { reset(); }
|
2019-05-29 21:10:08 +02:00
|
|
|
|
2019-07-03 21:17:35 +02:00
|
|
|
static u8 default_foreground_color;
|
|
|
|
|
static u8 default_background_color;
|
2019-05-29 21:10:08 +02:00
|
|
|
|
2019-01-15 07:30:24 +01:00
|
|
|
void reset()
|
|
|
|
|
{
|
2019-05-29 21:10:08 +02:00
|
|
|
foreground_color = default_foreground_color;
|
|
|
|
|
background_color = default_background_color;
|
|
|
|
|
flags = Flags::NoAttributes;
|
2019-01-15 07:30:24 +01:00
|
|
|
}
|
2019-07-03 21:17:35 +02:00
|
|
|
u8 foreground_color;
|
|
|
|
|
u8 background_color;
|
2019-05-29 21:10:08 +02:00
|
|
|
|
2019-06-07 17:13:23 +02:00
|
|
|
enum Flags {
|
2019-05-29 21:10:08 +02:00
|
|
|
NoAttributes = 0x00,
|
|
|
|
|
Bold = 0x01,
|
|
|
|
|
Italic = 0x02,
|
|
|
|
|
Underline = 0x04,
|
|
|
|
|
Negative = 0x08,
|
|
|
|
|
Blink = 0x10,
|
2019-07-01 18:14:08 +02:00
|
|
|
Touched = 0x20,
|
2019-05-29 21:10:08 +02:00
|
|
|
};
|
|
|
|
|
|
2019-07-01 18:14:08 +02:00
|
|
|
bool is_untouched() const { return !(flags & Touched); }
|
|
|
|
|
|
2019-05-29 21:10:08 +02:00
|
|
|
// TODO: it would be really nice if we had a helper for enums that
|
|
|
|
|
// exposed bit ops for class enums...
|
|
|
|
|
int flags = Flags::NoAttributes;
|
|
|
|
|
|
2019-02-03 14:00:48 +01:00
|
|
|
bool operator==(const Attribute& other) const
|
|
|
|
|
{
|
2019-05-29 21:10:08 +02:00
|
|
|
return foreground_color == other.foreground_color && background_color == other.background_color && flags == other.flags;
|
2019-02-03 14:00:48 +01:00
|
|
|
}
|
2019-02-04 08:53:53 +01:00
|
|
|
bool operator!=(const Attribute& other) const
|
|
|
|
|
{
|
|
|
|
|
return !(*this == other);
|
|
|
|
|
}
|
2019-01-15 07:30:24 +01:00
|
|
|
};
|
2019-01-15 04:30:55 +01:00
|
|
|
|
2019-01-25 01:27:02 +01:00
|
|
|
struct Line {
|
2019-07-03 21:17:35 +02:00
|
|
|
explicit Line(u16 columns);
|
2019-01-25 01:27:02 +01:00
|
|
|
~Line();
|
2019-02-03 16:11:28 +01:00
|
|
|
void clear(Attribute);
|
2019-01-25 02:09:29 +01:00
|
|
|
bool has_only_one_background_color() const;
|
2019-07-03 21:17:35 +02:00
|
|
|
void set_length(u16);
|
|
|
|
|
u8* characters { nullptr };
|
2019-01-25 01:27:02 +01:00
|
|
|
Attribute* attributes { nullptr };
|
2019-01-25 02:09:29 +01:00
|
|
|
bool dirty { false };
|
2019-07-03 21:17:35 +02:00
|
|
|
u16 m_length { 0 };
|
2019-01-25 01:27:02 +01:00
|
|
|
};
|
2019-05-28 11:53:16 +02:00
|
|
|
Line& line(size_t index)
|
|
|
|
|
{
|
|
|
|
|
ASSERT(index < m_rows);
|
|
|
|
|
return *m_lines[index];
|
|
|
|
|
}
|
2019-06-23 09:18:17 +02:00
|
|
|
const Line& line(size_t index) const
|
|
|
|
|
{
|
|
|
|
|
ASSERT(index < m_rows);
|
|
|
|
|
return *m_lines[index];
|
|
|
|
|
}
|
2019-01-25 01:27:02 +01:00
|
|
|
|
2019-05-29 10:53:21 -07:00
|
|
|
Vector<OwnPtr<Line>> m_lines;
|
|
|
|
|
|
2019-06-23 09:18:17 +02:00
|
|
|
BufferPosition m_selection_start;
|
|
|
|
|
BufferPosition m_selection_end;
|
|
|
|
|
|
2019-05-29 10:53:21 -07:00
|
|
|
int m_scroll_region_top { 0 };
|
|
|
|
|
int m_scroll_region_bottom { 0 };
|
2019-01-15 04:30:55 +01:00
|
|
|
|
2019-07-03 21:17:35 +02:00
|
|
|
u16 m_columns { 0 };
|
|
|
|
|
u16 m_rows { 0 };
|
2019-01-15 04:30:55 +01:00
|
|
|
|
2019-07-08 19:01:02 +02:00
|
|
|
u16 m_cursor_row { 0 };
|
|
|
|
|
u16 m_cursor_column { 0 };
|
|
|
|
|
u16 m_saved_cursor_row { 0 };
|
|
|
|
|
u16 m_saved_cursor_column { 0 };
|
2019-01-23 19:58:45 +01:00
|
|
|
bool m_stomp { false };
|
2019-01-15 07:30:24 +01:00
|
|
|
|
2019-05-31 12:43:58 -07:00
|
|
|
bool m_should_beep { false };
|
|
|
|
|
|
2019-01-15 07:30:24 +01:00
|
|
|
Attribute m_current_attribute;
|
2019-01-15 04:30:55 +01:00
|
|
|
|
2019-07-03 21:17:35 +02:00
|
|
|
void execute_escape_sequence(u8 final);
|
2019-01-25 05:51:39 +01:00
|
|
|
void execute_xterm_command();
|
2019-01-15 04:30:55 +01:00
|
|
|
|
2019-06-07 17:13:23 +02:00
|
|
|
enum EscapeState {
|
2019-01-15 04:30:55 +01:00
|
|
|
Normal,
|
|
|
|
|
ExpectBracket,
|
|
|
|
|
ExpectParameter,
|
|
|
|
|
ExpectIntermediate,
|
|
|
|
|
ExpectFinal,
|
2019-01-25 05:51:39 +01:00
|
|
|
|
|
|
|
|
ExpectXtermParameter1,
|
|
|
|
|
ExpectXtermParameter2,
|
|
|
|
|
ExpectXtermFinal,
|
2019-01-15 04:30:55 +01:00
|
|
|
};
|
|
|
|
|
EscapeState m_escape_state { Normal };
|
2019-07-03 21:17:35 +02:00
|
|
|
Vector<u8> m_parameters;
|
|
|
|
|
Vector<u8> m_intermediates;
|
|
|
|
|
Vector<u8> m_xterm_param1;
|
|
|
|
|
Vector<u8> m_xterm_param2;
|
2019-06-06 11:42:05 +02:00
|
|
|
Vector<bool> m_horizontal_tabs;
|
2019-07-03 21:17:35 +02:00
|
|
|
u8 m_final { 0 };
|
2019-01-15 04:30:55 +01:00
|
|
|
bool m_belling { false };
|
|
|
|
|
|
|
|
|
|
int m_pixel_width { 0 };
|
|
|
|
|
int m_pixel_height { 0 };
|
2019-01-15 07:39:51 +01:00
|
|
|
|
|
|
|
|
int m_inset { 2 };
|
|
|
|
|
int m_line_spacing { 4 };
|
2019-01-17 16:19:49 +01:00
|
|
|
int m_line_height { 0 };
|
|
|
|
|
|
2019-02-10 14:28:39 +01:00
|
|
|
int m_ptm_fd { -1 };
|
|
|
|
|
|
2019-03-14 18:33:21 +01:00
|
|
|
bool m_swallow_current { false };
|
|
|
|
|
|
2019-01-17 17:38:04 +01:00
|
|
|
bool m_in_active_window { false };
|
2019-02-10 14:28:39 +01:00
|
|
|
bool m_need_full_flush { false };
|
2019-01-17 17:38:04 +01:00
|
|
|
|
2019-04-10 17:35:43 +02:00
|
|
|
CNotifier m_notifier;
|
2019-02-19 01:42:53 +01:00
|
|
|
|
2019-07-03 21:17:35 +02:00
|
|
|
u8 m_opacity { 255 };
|
2019-02-19 01:42:53 +01:00
|
|
|
bool m_needs_background_fill { true };
|
2019-03-30 21:40:27 +01:00
|
|
|
bool m_cursor_blink_state { true };
|
2019-03-06 11:03:10 +01:00
|
|
|
|
|
|
|
|
int m_glyph_width { 0 };
|
2019-03-30 21:40:27 +01:00
|
|
|
|
2019-04-12 00:09:45 +02:00
|
|
|
CTimer m_cursor_blink_timer;
|
2019-05-31 14:51:06 -07:00
|
|
|
CTimer m_visual_beep_timer;
|
2019-06-21 18:37:47 +02:00
|
|
|
RefPtr<CConfigFile> m_config;
|
2019-06-11 07:31:47 +02:00
|
|
|
|
2019-07-03 21:17:35 +02:00
|
|
|
u8 m_last_char { 0 };
|
2019-01-15 04:30:55 +01:00
|
|
|
};
|