2019-01-15 04:30:55 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2019-09-06 15:34:26 +02:00
|
|
|
#include <AK/String.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-07-18 10:15:00 +02:00
|
|
|
#include <LibDraw/GraphicsBitmap.h>
|
|
|
|
|
#include <LibDraw/Rect.h>
|
2019-07-24 09:36:58 +02:00
|
|
|
#include <LibGUI/GFrame.h>
|
2019-08-12 17:32:16 +02:00
|
|
|
#include <LibVT/Terminal.h>
|
2019-01-15 04:30:55 +01:00
|
|
|
|
2019-08-19 19:12:34 +02:00
|
|
|
class GScrollBar;
|
|
|
|
|
|
2019-08-13 13:21:58 +02:00
|
|
|
class TerminalWidget final : public GFrame
|
2019-08-12 17:32:16 +02:00
|
|
|
, public VT::TerminalClient {
|
2019-08-13 13:21:58 +02:00
|
|
|
C_OBJECT(TerminalWidget)
|
2019-01-15 04:30:55 +01:00
|
|
|
public:
|
2019-10-21 20:28:30 +02:00
|
|
|
TerminalWidget(int ptm_fd, bool automatic_size_policy, RefPtr<CConfigFile> config);
|
2019-08-13 13:21:58 +02:00
|
|
|
virtual ~TerminalWidget() override;
|
2019-01-15 04:30:55 +01:00
|
|
|
|
2019-10-22 21:57:53 +02:00
|
|
|
void set_pty_master_fd(int fd);
|
2019-10-22 22:14:36 +02:00
|
|
|
void inject_string(const StringView& string)
|
|
|
|
|
{
|
|
|
|
|
m_terminal.inject_string(string);
|
|
|
|
|
flush_dirty_lines();
|
|
|
|
|
}
|
2019-10-22 21:57:53 +02:00
|
|
|
|
2019-01-15 04:30:55 +01:00
|
|
|
void create_window();
|
|
|
|
|
|
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;
|
2019-08-13 12:48:54 +02:00
|
|
|
bool selection_contains(const VT::Position&) const;
|
2019-06-23 09:18:17 +02:00
|
|
|
String selected_text() const;
|
2019-08-13 12:48:54 +02:00
|
|
|
VT::Position buffer_position_at(const Point&) const;
|
|
|
|
|
VT::Position normalized_selection_start() const;
|
|
|
|
|
VT::Position normalized_selection_end() const;
|
2019-06-23 09:18:17 +02:00
|
|
|
|
2019-08-20 20:11:56 +02:00
|
|
|
bool is_scrollable() const;
|
|
|
|
|
|
2019-11-20 21:33:23 +01:00
|
|
|
GAction& copy_action() { return *m_copy_action; }
|
|
|
|
|
GAction& paste_action() { return *m_paste_action; }
|
|
|
|
|
|
|
|
|
|
void copy();
|
|
|
|
|
void paste();
|
|
|
|
|
|
2019-10-21 20:14:51 +02:00
|
|
|
virtual bool accepts_focus() const override { return true; }
|
|
|
|
|
|
2019-10-21 22:07:59 +02:00
|
|
|
Function<void(const StringView&)> on_title_change;
|
2019-10-22 21:57:53 +02:00
|
|
|
Function<void()> on_command_exit;
|
2019-10-21 22:07:59 +02:00
|
|
|
|
2019-01-15 04:30:55 +01:00
|
|
|
private:
|
2019-08-12 17:32:16 +02:00
|
|
|
// ^GWidget
|
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;
|
2019-08-20 20:11:56 +02:00
|
|
|
virtual void mousewheel_event(GMouseEvent&) override;
|
2019-08-22 19:59:27 +02:00
|
|
|
virtual void doubleclick_event(GMouseEvent&) override;
|
2019-10-21 20:14:51 +02:00
|
|
|
virtual void focusin_event(CEvent&) override;
|
|
|
|
|
virtual void focusout_event(CEvent&) override;
|
2019-11-20 21:39:26 +01:00
|
|
|
virtual void context_menu_event(GContextMenuEvent&) override;
|
2019-02-10 14:28:39 +01:00
|
|
|
|
2019-08-12 17:32:16 +02:00
|
|
|
// ^TerminalClient
|
|
|
|
|
virtual void beep() override;
|
|
|
|
|
virtual void set_window_title(const StringView&) override;
|
|
|
|
|
virtual void terminal_did_resize(u16 columns, u16 rows) override;
|
2019-08-19 19:12:34 +02:00
|
|
|
virtual void terminal_history_changed() override;
|
2019-01-15 04:30:55 +01:00
|
|
|
|
2019-10-21 20:14:51 +02:00
|
|
|
void set_logical_focus(bool);
|
|
|
|
|
|
2019-07-03 21:17:35 +02:00
|
|
|
Rect glyph_rect(u16 row, u16 column);
|
|
|
|
|
Rect row_rect(u16 row);
|
2019-05-29 21:10:08 +02:00
|
|
|
|
2019-08-12 17:32:16 +02:00
|
|
|
void update_cursor();
|
|
|
|
|
void invalidate_cursor();
|
2019-01-15 04:30:55 +01:00
|
|
|
|
2019-08-19 19:12:34 +02:00
|
|
|
Size compute_base_size() const;
|
2019-08-25 11:20:32 -05:00
|
|
|
int first_selection_column_on_row(int row) const;
|
|
|
|
|
int last_selection_column_on_row(int row) const;
|
2019-08-19 19:12:34 +02:00
|
|
|
|
2019-08-12 17:32:16 +02:00
|
|
|
VT::Terminal m_terminal;
|
2019-01-15 04:30:55 +01:00
|
|
|
|
2019-08-13 12:48:54 +02:00
|
|
|
VT::Position m_selection_start;
|
|
|
|
|
VT::Position m_selection_end;
|
2019-01-15 07:30:24 +01:00
|
|
|
|
2019-05-31 12:43:58 -07:00
|
|
|
bool m_should_beep { false };
|
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-10-21 20:14:51 +02:00
|
|
|
bool m_has_logical_focus { false };
|
2019-01-17 17:38:04 +01:00
|
|
|
|
2019-09-22 00:31:54 +02:00
|
|
|
RefPtr<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-10-21 20:28:30 +02:00
|
|
|
bool m_automatic_size_policy { false };
|
2019-03-06 11:03:10 +01:00
|
|
|
|
|
|
|
|
int m_glyph_width { 0 };
|
2019-03-30 21:40:27 +01:00
|
|
|
|
2019-09-22 00:31:54 +02:00
|
|
|
RefPtr<CTimer> m_cursor_blink_timer;
|
|
|
|
|
RefPtr<CTimer> m_visual_beep_timer;
|
2019-06-21 18:37:47 +02:00
|
|
|
RefPtr<CConfigFile> m_config;
|
2019-08-19 19:12:34 +02:00
|
|
|
|
2019-09-22 00:31:54 +02:00
|
|
|
RefPtr<GScrollBar> m_scrollbar;
|
2019-11-15 23:48:58 +01:00
|
|
|
|
2019-11-20 21:33:23 +01:00
|
|
|
RefPtr<GAction> m_copy_action;
|
|
|
|
|
RefPtr<GAction> m_paste_action;
|
|
|
|
|
|
2019-11-20 21:39:26 +01:00
|
|
|
OwnPtr<GMenu> m_context_menu;
|
|
|
|
|
|
2019-11-15 23:48:58 +01:00
|
|
|
CElapsedTimer m_triple_click_timer;
|
2019-01-15 04:30:55 +01:00
|
|
|
};
|