neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
terminal.hpp
Go to the documentation of this file.
1// terminal.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2022 Leigh Johnston. All Rights Reserved.
5
6 This program is free software: you can redistribute it and / or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
26
27namespace neogfx
28{
29 class terminal : public scrollable_widget<framed_widget<widget<i_terminal>>>
30 {
32 public:
34 define_declared_event(TerminalResized, terminal_resized, size_type)
35 private:
37 private:
38 struct attribute
39 {
40 color ink;
41 color paper;
42 bool reverse = false;
43 bool blink = false;
44 bool underline = false;
46 };
47 struct buffer_line
48 {
49 std::u32string text;
50 mutable optional_glyph_text glyphs;
51 std::vector<attribute> attributes;
52 };
53 struct scrolling_region { coordinate_type top; coordinate_type bottom; };
54 enum class character_set
55 {
56 Unknown,
57 USASCII,
58 DECSpecial
59 };
60 enum class keypad_mode
61 {
62 Application,
63 Numeric
64 };
65 struct buffer
66 {
67 point_type bufferOrigin;
68 std::optional<point_type> cursorPos;
69 std::vector<buffer_line> lines;
70 coordinate_type defaultTabStop = 8;
71 std::optional<attribute> attribute;
72 bool originMode = true;
73 bool autoWrap = true;
74 bool bracketedPaste = false;
75 bool ansiMode = true;
76 character_set characterSet = character_set::USASCII;
77 keypad_mode keypadMode = keypad_mode::Numeric;
78 bool cursorKeysMode = false;
79 std::optional<scrolling_region> scrollingRegion;
80 mutable neogfx::cursor cursor;
81 };
82 public:
84 terminal(i_widget& aParent);
85 terminal(i_layout& aLayout);
87 public:
88 neogfx::size_policy size_policy() const override;
89 public:
90 void resized() override;
91 public:
92 rect scroll_area() const override;
93 size scroll_page() const override;
94 bool use_scrollbar_container_updater() const override;
95 public:
96 void paint(i_graphics_context& aGc) const override;
97 color palette_color(color_role aColorRole) const override;
98 public:
99 using base_type::font;
100 void set_font(optional_font const& aFont) override;
101 void set_text_format(optional_text_format const& aTextFormat) override;
102 public:
104 void focus_gained(focus_reason aFocusReason) override;
105 void focus_lost(focus_reason aFocusReason) override;
106 public:
107 void mouse_button_pressed(mouse_button aButton, const point& aPosition, key_modifiers_e aKeyModifiers) override;
108 void mouse_button_double_clicked(mouse_button aButton, const point& aPosition, key_modifiers_e aKeyModifiers) override;
109 void mouse_button_released(mouse_button aButton, const point& aPosition) override;
110 void mouse_moved(const point& aPosition, key_modifiers_e aKeyModifiers) override;
111 void mouse_entered(const point& aPosition) override;
112 void mouse_left() override;
114 public:
115 bool key_pressed(scan_code_e aScanCode, key_code_e aKeyCode, key_modifiers_e aKeyModifiers) override;
116 bool key_released(scan_code_e aScanCode, key_code_e aKeyCode, key_modifiers_e aKeyModifiers) override;
117 bool text_input(i_string const& aText) override;
118 public:
119 size_type terminal_size() const final;
120 public:
121 void output(i_string const& aOutput) final;
123 private:
124 void init();
125 buffer& active_buffer() const;
126 void enable_alternate_buffer();
127 void disable_alternate_buffer();
128 neogfx::font const& font(font_style aStyle) const;
129 neogfx::font const& normal_font() const;
130 neogfx::font const& bold_font() const;
131 neogfx::font const& italic_font() const;
132 neogfx::font const& bold_italic_font() const;
133 attribute default_attribute() const;
134 attribute active_attribute() const;
135 size character_extents() const;
136 void animate();
137 void erase_in_display(point_type const& aBufferPosStart, point_type const& aBufferPosEnd);
138 char32_t to_unicode(char32_t aCharacter) const;
139 buffer_line& line(coordinate_type aLine);
140 char32_t& character(point_type const& aBufferPos);
141 void output_character(char32_t aCharacter, std::optional<attribute> const& aAttribute = {});
142 point_type buffer_origin() const;
143 void set_buffer_origin(point_type aBufferOrigin);
144 point_type buffer_pos() const;
145 point_type to_buffer_pos(point_type aCursorPos) const;
146 point_type cursor_pos() const;
147 bool set_cursor_pos(point_type aCursorPos, bool aExtendBuffer = true);
148 void update_cursor();
149 rect cursor_rect() const;
150 void make_cursor_visible(bool aToBufferOrigin = true);
151 void draw_cursor(i_graphics_context& aGc) const;
152 private:
153 size_type iTerminalSize;
154 size_type iBufferSize;
155 mutable optional_font iNormalFont;
156 mutable optional_font iBoldFont;
157 mutable optional_font iItalicFont;
158 mutable optional_font iBoldItalicFont;
159 mutable optional_size iCharacterExtents;
160 optional_text_format iTextFormat;
161 buffer iPrimaryBuffer = {};
162 buffer iAlternateBuffer = {};
163 buffer* iActiveBuffer = &iPrimaryBuffer;
164 std::optional<std::string> iEscapeSequence;
165 mutable bool iOutputting = false;
166 uint64_t iCursorAnimationStartTime;
167 widget_timer iAnimator;
168 sink iSink;
169 };
170}
void set_font(optional_font const &aFont) override
void set_text_format(optional_text_format const &aTextFormat) override
void output(i_string const &aOutput) final
neogfx::mouse_cursor mouse_cursor() const override
neogfx::size_policy size_policy() const override
rect scroll_area() const override
void mouse_button_released(mouse_button aButton, const point &aPosition) override
terminal(i_widget &aParent)
void mouse_left() override
void mouse_button_double_clicked(mouse_button aButton, const point &aPosition, key_modifiers_e aKeyModifiers) override
void mouse_entered(const point &aPosition) override
bool use_scrollbar_container_updater() const override
void paint(i_graphics_context &aGc) const override
void focus_gained(focus_reason aFocusReason) override
terminal(i_layout &aLayout)
size_type terminal_size() const final
neogfx::focus_policy focus_policy() const override
void focus_lost(focus_reason aFocusReason) override
color palette_color(color_role aColorRole) const override
bool key_pressed(scan_code_e aScanCode, key_code_e aKeyCode, key_modifiers_e aKeyModifiers) override
size scroll_page() const override
void mouse_button_pressed(mouse_button aButton, const point &aPosition, key_modifiers_e aKeyModifiers) override
void resized() override
bool key_released(scan_code_e aScanCode, key_code_e aKeyCode, key_modifiers_e aKeyModifiers) override
bool text_input(i_string const &aText) override
void mouse_moved(const point &aPosition, key_modifiers_e aKeyModifiers) override
const neogfx::font & font() const override
Definition widget.ipp:1572
bool underline(glyph_char const &g)
std::optional< glyph_text > optional_glyph_text
basic_line< coordinate > line
mouse_button
Definition i_mouse.hpp:31
font_style
Definition font.hpp:35
Definition plf_hive.h:79
#define meta_object(...)
Definition i_object.hpp:28
#define define_declared_event(name, declName,...)
Definition event.hpp:195