FTXUI  2.0.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 bool automerge : 1;
32
34 : blink(false),
35 bold(false),
36 dim(false),
37 inverted(false),
38 underlined(false),
39 automerge(false) {}
40};
41
42/// @brief Define how the Screen's dimensions should look like.
43/// @ingroup screen
44namespace Dimension {
47} // namespace Dimension
48
49/// @brief A rectangular grid of Pixel.
50/// @ingroup screen
51class Screen {
52 public:
53 // Constructors:
54 Screen(int dimx, int dimy);
55 static Screen Create(Dimensions dimension);
56 static Screen Create(Dimensions width, Dimensions height);
57
58 // Node write into the screen using Screen::at.
59 std::string& at(int x, int y);
60 Pixel& PixelAt(int x, int y);
61
62 // Convert the screen into a printable string in the terminal.
63 std::string ToString();
64 void Print();
65
66 // Get screen dimensions.
67 int dimx() const { return dimx_; }
68 int dimy() const { return dimy_; }
69
70 // Move the terminal cursor n-lines up with n = dimy().
71 std::string ResetPosition(bool clear = false);
72
73 // Fill with space.
74 void Clear();
75
76 void ApplyShader();
78
79 struct Cursor {
80 int x = 0;
81 int y = 0;
82 };
83 Cursor cursor() const { return cursor_; }
85
86 protected:
87 int dimx_;
88 int dimy_;
89 std::vector<std::vector<Pixel>> pixels_;
91};
92
93} // namespace ftxui
94
95#endif /* end of include guard: FTXUI_SCREEN_SCREEN */
96
97// Copyright 2020 Arthur Sonzogni. All rights reserved.
98// Use of this source code is governed by the MIT license that can be found in
99// the LICENSE file.
A class representing terminal colors.
Definition color.hpp:17
A rectangular grid of Pixel.
Definition screen.hpp:51
void ApplyShader()
Definition screen.cpp:459
int dimy() const
Definition screen.hpp:68
void SetCursor(Cursor cursor)
Definition screen.hpp:84
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:434
static Screen Create(Dimensions dimension)
Create a screen with the given dimension.
Definition screen.cpp:348
Pixel & PixelAt(int x, int y)
Access a Pixel at a given position.
Definition screen.cpp:411
std::string & at(int x, int y)
Access a character a given position.
Definition screen.cpp:404
Screen(int dimx, int dimy)
Definition screen.cpp:352
std::string ToString()
Definition screen.cpp:371
Cursor cursor() const
Definition screen.hpp:83
void Print()
Definition screen.cpp:397
Cursor cursor_
Definition screen.hpp:90
void Clear()
Clear all the pixel from the screen.
Definition screen.cpp:451
int dimx() const
Definition screen.hpp:67
std::vector< std::vector< Pixel > > pixels_
Definition screen.hpp:89
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
bool automerge
Definition screen.hpp:31