FTXUI  4.0.0
C++ functional terminal UI.
Loading...
Searching...
No Matches
screen.hpp
Go to the documentation of this file.
1#ifndef FTXUI_SCREEN_SCREEN_HPP
2#define FTXUI_SCREEN_SCREEN_HPP
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 bool operator==(const Pixel& other) const;
18
19 // The graphemes stored into the pixel. To support combining characters,
20 // like: a⃦, this can potentially contains multiple codepoitns.
21 std::string character = " ";
22
23 // Colors:
26
27 // A bit field representing the style:
28 bool blink : 1;
29 bool bold : 1;
30 bool dim : 1;
31 bool inverted : 1;
32 bool underlined : 1;
34 bool strikethrough : 1;
35 bool automerge : 1;
36
38 : blink(false),
39 bold(false),
40 dim(false),
41 inverted(false),
42 underlined(false),
43 underlined_double(false),
44 strikethrough(false),
45 automerge(false) {}
46};
47
48/// @brief Define how the Screen's dimensions should look like.
49/// @ingroup screen
50namespace Dimension {
53} // namespace Dimension
54
55/// @brief A rectangular grid of Pixel.
56/// @ingroup screen
57class Screen {
58 public:
59 // Constructors:
60 Screen(int dimx, int dimy);
61 static Screen Create(Dimensions dimension);
62 static Screen Create(Dimensions width, Dimensions height);
63
64 // Node write into the screen using Screen::at.
65 std::string& at(int x, int y);
66 Pixel& PixelAt(int x, int y);
67
68 // Convert the screen into a printable string in the terminal.
69 std::string ToString();
70 void Print();
71
72 // Get screen dimensions.
73 int dimx() const { return dimx_; }
74 int dimy() const { return dimy_; }
75
76 // Move the terminal cursor n-lines up with n = dimy().
77 std::string ResetPosition(bool clear = false) const;
78
79 // Fill with space.
80 void Clear();
81
82 void ApplyShader();
83
84 struct Cursor {
85 int x = 0;
86 int y = 0;
87
98 };
99 Cursor cursor() const { return cursor_; }
101
103
104 protected:
105 int dimx_;
106 int dimy_;
107 std::vector<std::vector<Pixel>> pixels_;
109};
110
111} // namespace ftxui
112
113#endif // FTXUI_SCREEN_SCREEN_HPP
114
115// Copyright 2020 Arthur Sonzogni. All rights reserved.
116// Use of this source code is governed by the MIT license that can be found in
117// the LICENSE file.
A class representing terminal colors.
Definition color.hpp:17
A rectangular grid of Pixel.
Definition screen.hpp:57
void ApplyShader()
Definition screen.cpp:521
int dimy() const
Definition screen.hpp:74
void SetCursor(Cursor cursor)
Definition screen.hpp:100
static Screen Create(Dimensions dimension)
Create a screen with the given dimension.
Definition screen.cpp:405
Pixel & PixelAt(int x, int y)
Access a Pixel at a given position.
Definition screen.cpp:468
std::string & at(int x, int y)
Access a character a given position.
Definition screen.cpp:461
Screen(int dimx, int dimy)
Definition screen.cpp:409
std::string ToString()
Definition screen.cpp:428
Cursor cursor() const
Definition screen.hpp:99
std::string ResetPosition(bool clear=false) const
Return a string to be printed in order to reset the cursor position to the beginning of the screen.
Definition screen.cpp:491
void Print()
Definition screen.cpp:454
Cursor cursor_
Definition screen.hpp:108
void Clear()
Clear all the pixel from the screen.
Definition screen.cpp:510
int dimx() const
Definition screen.hpp:73
std::vector< std::vector< Pixel > > pixels_
Definition screen.hpp:107
Dimensions Fixed(int)
Dimensions Full()
A unicode character and its associated style.
Definition screen.hpp:16
bool operator==(const Pixel &other) const
Definition screen.cpp:371
bool inverted
Definition screen.hpp:31
bool strikethrough
Definition screen.hpp:34
Color foreground_color
Definition screen.hpp:25
Color background_color
Definition screen.hpp:24
std::string character
Definition screen.hpp:21
bool underlined
Definition screen.hpp:32
bool automerge
Definition screen.hpp:35
bool underlined_double
Definition screen.hpp:33