9
9
#include < string> // for string, basic_string, allocator
10
10
#include < vector> // for vector
11
11
12
- #include " ftxui/screen/box.hpp" // for Box
13
12
#include " ftxui/screen/color.hpp" // for Color, Color::Default
13
+ #include " ftxui/screen/image.hpp" // for Pixel, Image
14
14
#include " ftxui/screen/terminal.hpp" // for Dimensions
15
15
16
16
namespace ftxui {
17
17
18
- // / @brief A unicode character and its associated style.
19
- // / @ingroup screen
20
- struct Pixel {
21
- Pixel ()
22
- : blink(false ),
23
- bold (false ),
24
- dim(false ),
25
- inverted(false ),
26
- underlined(false ),
27
- underlined_double(false ),
28
- strikethrough(false ),
29
- automerge(false ) {}
30
-
31
- // A bit field representing the style:
32
- bool blink : 1 ;
33
- bool bold : 1 ;
34
- bool dim : 1 ;
35
- bool inverted : 1 ;
36
- bool underlined : 1 ;
37
- bool underlined_double : 1 ;
38
- bool strikethrough : 1 ;
39
- bool automerge : 1 ;
40
-
41
- // The hyperlink associated with the pixel.
42
- // 0 is the default value, meaning no hyperlink.
43
- uint8_t hyperlink = 0 ;
44
-
45
- // The graphemes stored into the pixel. To support combining characters,
46
- // like: a⃦, this can potentially contain multiple codepoints.
47
- std::string character = " " ;
48
-
49
- // Colors:
50
- Color background_color = Color::Default;
51
- Color foreground_color = Color::Default;
52
- };
53
-
54
18
// / @brief Define how the Screen's dimensions should look like.
55
19
// / @ingroup screen
56
20
namespace Dimension {
@@ -60,36 +24,24 @@ Dimensions Full();
60
24
61
25
// / @brief A rectangular grid of Pixel.
62
26
// / @ingroup screen
63
- class Screen {
27
+ class Screen : public Image {
64
28
public:
65
29
// Constructors:
66
30
Screen (int dimx, int dimy);
67
31
static Screen Create (Dimensions dimension);
68
32
static Screen Create (Dimensions width, Dimensions height);
69
33
70
- // Access a character in the grid at a given position.
71
- std::string& at (int x, int y);
72
- const std::string& at (int x, int y) const ;
73
-
74
- // Access a cell (Pixel) in the grid at a given position.
75
- Pixel& PixelAt (int x, int y);
76
- const Pixel& PixelAt (int x, int y) const ;
77
-
78
34
std::string ToString () const ;
79
35
80
36
// Print the Screen on to the terminal.
81
37
void Print () const ;
82
38
83
- // Get screen dimensions.
84
- int dimx () const { return dimx_; }
85
- int dimy () const { return dimy_; }
39
+ // Fill the screen with space and reset any screen state, like hyperlinks, and cursor
40
+ void Clear ();
86
41
87
42
// Move the terminal cursor n-lines up with n = dimy().
88
43
std::string ResetPosition (bool clear = false ) const ;
89
44
90
- // Fill the screen with space.
91
- void Clear ();
92
-
93
45
void ApplyShader ();
94
46
95
47
struct Cursor {
@@ -107,6 +59,7 @@ class Screen {
107
59
};
108
60
Shape shape;
109
61
};
62
+
110
63
Cursor cursor () const { return cursor_; }
111
64
void SetCursor (Cursor cursor) { cursor_ = cursor; }
112
65
@@ -115,12 +68,7 @@ class Screen {
115
68
uint8_t RegisterHyperlink (const std::string& link);
116
69
const std::string& Hyperlink (uint8_t id) const ;
117
70
118
- Box stencil;
119
-
120
71
protected:
121
- int dimx_;
122
- int dimy_;
123
- std::vector<std::vector<Pixel>> pixels_;
124
72
Cursor cursor_;
125
73
std::vector<std::string> hyperlinks_ = {" " };
126
74
};
0 commit comments