TermOx
terminal.hpp
1 #ifndef TERMOX_TERMINAL_TERMINAL_HPP
2 #define TERMOX_TERMINAL_TERMINAL_HPP
3 #include <cstdint>
4 
5 #include <signals_light/signal.hpp>
6 
7 #include <termox/painter/color.hpp>
8 #include <termox/painter/glyph.hpp>
9 #include <termox/system/event_fwd.hpp>
10 #include <termox/terminal/detail/screen_buffers.hpp>
11 #include <termox/terminal/dynamic_color_engine.hpp>
12 #include <termox/terminal/key_mode.hpp>
13 #include <termox/terminal/mouse_mode.hpp>
14 #include <termox/terminal/signals.hpp>
15 #include <termox/widget/area.hpp>
16 
17 namespace ox {
18 
19 class Terminal {
20  public:
21  inline static sl::Signal<void(Palette const&)> palette_changed;
22 
23  inline static detail::Screen_buffers screen_buffers{Area{0, 0}};
24 
25  public:
27 
51  static void initialize(Mouse_mode mouse_mode = Mouse_mode::Basic,
52  Key_mode key_mode = Key_mode::Normal,
53  Signals signals = Signals::On);
54 
56 
57  static void uninitialize();
58 
60  [[nodiscard]] static auto area() -> Area;
61 
63 
65  static void refresh();
66 
68 
69  static void update_color_stores(Color c, True_color tc);
70 
72 
73  static void repaint_color(Color c);
74 
76  static void set_palette(Palette colors);
77 
79 
81  static auto palette_append(Color_definition::Value_t value) -> Color;
82 
84  [[nodiscard]] static auto current_palette() -> Palette const&;
85 
87  static void show_cursor(bool show = true);
88 
90 
91  static void move_cursor(Point point);
92 
94 
95  [[nodiscard]] static auto color_count() -> std::uint16_t;
96 
98  [[nodiscard]] static auto has_true_color() -> bool;
99 
101 
103  [[nodiscard]] static auto read_input() -> Event;
104 
106 
107  static void flag_full_repaint();
108 
110  static void flush_screen();
111 
113  static void stop_dynamic_color_engine();
114 
116 
118  static void handle_signint(bool x);
119 
120  private:
121  inline static Palette palette_;
122  inline static Dynamic_color_engine dynamic_color_engine_;
123  inline static bool is_initialized_ = false;
124  inline static bool full_repaint_ = false;
125  inline static bool handle_sigint_ = true;
126 };
127 
128 } // namespace ox
129 #endif // TERMOX_TERMINAL_TERMINAL_HPP
Color numbers [0 - 180] are valid.
Definition: color.hpp:16
Event loop that manages posting of Dynamic_color_events.
Definition: dynamic_color_engine.hpp:15
Definition: terminal.hpp:19
static void repaint_color(Color c)
Repaints all Glyphs with c in their Brush to the screen.
Definition: terminal.cpp:226
static auto palette_append(Color_definition::Value_t value) -> Color
Append a Color_definition::Value_t to the current color palette.
Definition: terminal.cpp:251
static auto read_input() -> Event
Wait for user input, and return with a corresponding Event.
Definition: terminal.cpp:286
static void show_cursor(bool show=true)
Set whether or not the cursor is visible on screen.
Definition: terminal.cpp:267
static void flag_full_repaint()
Sets a flag so that the next call to refresh() will repaint every cell.
Definition: terminal.cpp:292
static void refresh()
Update the screen to reflect change made by Painter since last call.
Definition: terminal.cpp:207
static auto area() -> Area
Return the Area of the terminal screen.
Definition: terminal.cpp:205
static auto color_count() -> std::uint16_t
Return the number of colors in the terminal's built in palette.
Definition: terminal.cpp:279
static void flush_screen()
Flushes all of the staged changes to the screen and sets the cursor.
Definition: terminal.cpp:294
static void initialize(Mouse_mode mouse_mode=Mouse_mode::Basic, Key_mode key_mode=Key_mode::Normal, Signals signals=Signals::On)
Initializes the terminal screen into curses mode.
Definition: terminal.cpp:183
static void stop_dynamic_color_engine()
Send exit flag and wait for Dynamic_color_engine thread to shutdown.
Definition: terminal.cpp:306
static void uninitialize()
Reset the terminal to its state before initialize() was called.
Definition: terminal.cpp:197
static void set_palette(Palette colors)
Change Color definitions.
Definition: terminal.cpp:232
static auto current_palette() -> Palette const &
Return a copy of the currently set color palette.
Definition: terminal.cpp:265
static void move_cursor(Point point)
Moves the cursor to Point point on screen.
Definition: terminal.cpp:273
static void update_color_stores(Color c, True_color tc)
Update a Color Palette value.
Definition: terminal.cpp:220
static void handle_signint(bool x)
If set true, will properly uninitialize the screen on SIGINT.
Definition: terminal.cpp:308
static auto has_true_color() -> bool
Return true if this terminal supports true color.
Definition: terminal.cpp:284
Holds the current and next screen buffers as Canvas objects.
Definition: screen_buffers.hpp:11