FTXUI  0.11.0
C++ functional terminal UI.
Loading...
Searching...
No Matches
screen.hpp
Go to the documentation of this file.
1#ifndef FTXUI_SCREEN_SCREEN
2#define FTXUI_SCREEN_SCREEN
3
4#include <memory>
5#include <string> // for string, allocator, basic_string
6#include <vector> // for vector
7
8#include "ftxui/screen/box.hpp" // for Box
9#include "ftxui/screen/color.hpp" // for Color, Color::Default
10#include "ftxui/screen/terminal.hpp" // for Dimensions
11
12namespace ftxui {
13
14/// @brief A unicode character and its associated style.
15/// @ingroup screen
16struct Pixel {
17 // The graphemes stored into the pixel. To support combining characters,
18 // like: a⃦, this can potentially contains multiple codepoitns.
19 std::string character = " ";
20
21 // Colors:
24
25 // A bit field representing the style:
26 bool blink : 1;
27 bool bold : 1;
28 bool dim : 1;
29 bool inverted : 1;
30 bool underlined : 1;
31
33 : blink(false),
34 bold(false),
35 dim(false),
36 inverted(false),
37 underlined(false) {}
38};
39
40/// @brief Define how the Screen's dimensions should look like.
41/// @ingroup screen
42namespace Dimension {
45} // namespace Dimension
46
47/// @brief A rectangular grid of Pixel.
48/// @ingroup screen
49class Screen {
50 public:
51 // Constructors:
52 Screen(int dimx, int dimy);
53 static Screen Create(Dimensions dimension);
54 static Screen Create(Dimensions width, Dimensions height);
55
56 // Node write into the screen using Screen::at.
57 std::string& at(int x, int y);
58 Pixel& PixelAt(int x, int y);
59
60 // Convert the screen into a printable string in the terminal.
61 std::string ToString();
62 void Print();
63
64 // Get screen dimensions.
65 int dimx() { return dimx_; }
66 int dimy() { return dimy_; }
67
68 // Move the terminal cursor n-lines up with n = dimy().
69 std::string ResetPosition(bool clear = false);
70
71 // Fill with space.
72 void Clear();
73
74 void ApplyShader();
76
77 struct Cursor {
78 int x = 0;
79 int y = 0;
80 };
81 Cursor cursor() const { return cursor_; }
83
84 protected:
85 int dimx_;
86 int dimy_;
87 std::vector<std::vector<Pixel>> pixels_;
89};
90
91} // namespace ftxui
92
93#endif /* end of include guard: FTXUI_SCREEN_SCREEN */
94
95// Copyright 2020 Arthur Sonzogni. All rights reserved.
96// Use of this source code is governed by the MIT license that can be found in
97// the LICENSE file.
A class representing terminal colors.
Definition color.hpp:17
A rectangular grid of Pixel.
Definition screen.hpp:49
void ApplyShader()
Definition screen.cpp:455
void SetCursor(Cursor cursor)
Definition screen.hpp:82
std::string ResetPosition(bool clear=false)
Return a string to be printed in order to reset the cursor position to the beginning of the screen.
Definition screen.cpp:430
static Screen Create(Dimensions dimension)
Create a screen with the given dimension.
Definition screen.cpp:344
Pixel & PixelAt(int x, int y)
Access a Pixel at a given position.
Definition screen.cpp:407
std::string & at(int x, int y)
Access a character a given position.
Definition screen.cpp:400
Screen(int dimx, int dimy)
Definition screen.cpp:348
std::string ToString()
Definition screen.cpp:367
Cursor cursor() const
Definition screen.hpp:81
void Print()
Definition screen.cpp:393
Cursor cursor_
Definition screen.hpp:88
void Clear()
Clear all the pixel from the screen.
Definition screen.cpp:447
std::vector< std::vector< Pixel > > pixels_
Definition screen.hpp:87
Dimensions Fixed(int)
Dimensions Full()
A unicode character and its associated style.
Definition screen.hpp:16
bool inverted
Definition screen.hpp:29
Color foreground_color
Definition screen.hpp:23
Color background_color
Definition screen.hpp:22
std::string character
Definition screen.hpp:19
bool underlined
Definition screen.hpp:30