FTXUI 7.1.0
C++ functional terminal UI.
Loading...
Searching...
No Matches
screen.hpp
Go to the documentation of this file.
1// Copyright 2020 Arthur Sonzogni. All rights reserved.
2// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
4#ifndef FTXUI_SCREEN_SCREEN_HPP
5#define FTXUI_SCREEN_SCREEN_HPP
6
7#include <cstdint> // for uint8_t
8#include <functional> // for function
9#include <string> // for string, basic_string, allocator
10#include <vector> // for vector
11
12#include "ftxui/screen/surface.hpp" // for Surface
13#include "ftxui/screen/terminal.hpp" // for Dimensions
14#include "ftxui/util/export.hpp" // for FTXUI_EXPORT
15
16namespace ftxui {
17
18/// @brief Define how the Screen's dimensions should look like.
19/// @ingroup screen
20namespace Dimension {
21FTXUI_EXPORT(SCREEN) Dimensions Fixed(int);
22FTXUI_EXPORT(SCREEN) Dimensions Full();
23} // namespace Dimension
24
25/// @brief A rectangular grid of Cell.
26/// @ingroup screen
27class FTXUI_EXPORT(SCREEN) Screen : public Surface {
28 public:
29 // Constructors:
30 Screen(int dimx, int dimy);
31 static Screen Create(Dimensions dimension);
32 static Screen Create(Dimensions width, Dimensions height);
33
34 // Destructor:
35 ~Screen() override = default;
36
37 // Copy:
38 Screen(const Screen&) = default;
39 Screen& operator=(const Screen&) = default;
40
41 std::string ToString() const;
42 void ToString(std::string& ss) const;
43 // Update the terminal from |previous| to this screen, printing only the cells
44 // that changed. The cursor must be at the top-left corner of |previous|.
45 void ToString(std::string& ss, const Screen& previous) const;
46
47 // Print the Screen on to the terminal.
48 void Print() const;
49
50 // Fill the screen with space and reset any screen state, like hyperlinks, and
51 // cursor
52 void Clear();
53
54 // Move the terminal cursor n-lines up with n = dimy().
55 std::string ResetPosition(bool clear = false) const;
56 void ResetPosition(std::string& ss, bool clear = false) const;
57
58 void ApplyShader();
59
60 struct Cursor {
61 int x = 0;
62 int y = 0;
63
64 enum Shape : uint8_t {
65 Hidden = 0,
66 BlockBlinking = 1,
67 Block = 2,
68 UnderlineBlinking = 3,
69 Underline = 4,
70 BarBlinking = 5,
71 Bar = 6,
72 };
73 Shape shape = Hidden;
74 };
75
76 Cursor cursor() const { return cursor_; }
77 void SetCursor(Cursor cursor) { cursor_ = cursor; }
78
79 // ABI Reserve:
80 void Reserved1() override;
81 void Reserved2() override;
82 void Reserved3() override;
83 void Reserved4() override;
84 void Reserved5() override;
85 void Reserved6() override;
86 void Reserved7() override;
87 void Reserved8() override;
88
89 // Store an hyperlink in the screen. Return the id of the hyperlink. The id is
90 // used to identify the hyperlink when the user click on it.
91 uint8_t RegisterHyperlink(std::string_view link);
92 const std::string& Hyperlink(uint8_t id) const;
93
94 using SelectionStyle = std::function<void(Cell&)>;
95 const SelectionStyle& GetSelectionStyle() const;
96 void SetSelectionStyle(SelectionStyle decorator);
97
98 protected:
99 Cursor cursor_;
100 std::vector<std::string> hyperlinks_ = {""};
101
102 // The current selection style. This is overridden by various dom elements.
103 SelectionStyle selection_style_ = [](Cell& cell) { cell.inverted ^= true; };
104};
105
106} // namespace ftxui
107
108#endif // FTXUI_SCREEN_SCREEN_HPP
#define FTXUI_EXPORT(component)
Definition export.hpp:24
The FTXUI ftxui::Dimension:: namespace.
The FTXUI ftxui:: namespace.
Definition animation.hpp:11
int y
Definition elements.hpp:134