FTXUI  5.0.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/image.hpp" // for Pixel, Image
13#include "ftxui/screen/terminal.hpp" // for Dimensions
14#include "ftxui/util/autoreset.hpp" // for AutoReset
15
16namespace ftxui {
17
18/// @brief Define how the Screen's dimensions should look like.
19/// @ingroup screen
20namespace Dimension {
21Dimensions Fixed(int);
22Dimensions Full();
23} // namespace Dimension
24
25/// @brief A rectangular grid of Pixel.
26/// @ingroup screen
27class Screen : public Image {
28 public:
29 // Constructors:
30 Screen(int dimx, int dimy);
32 static Screen Create(Dimensions width, Dimensions height);
33
34 std::string ToString() const;
35
36 // Print the Screen on to the terminal.
37 void Print() const;
38
39 // Fill the screen with space and reset any screen state, like hyperlinks, and
40 // cursor
41 void Clear();
42
43 // Move the terminal cursor n-lines up with n = dimy().
44 std::string ResetPosition(bool clear = false) const;
45
46 void ApplyShader();
47
48 struct Cursor {
49 int x = 0;
50 int y = 0;
51
62 };
63
64 Cursor cursor() const { return cursor_; }
66
67 // Store an hyperlink in the screen. Return the id of the hyperlink. The id is
68 // used to identify the hyperlink when the user click on it.
69 uint8_t RegisterHyperlink(const std::string& link);
70 const std::string& Hyperlink(uint8_t id) const;
71
72 using SelectionStyle = std::function<void(Pixel&)>;
73 const SelectionStyle& GetSelectionStyle() const;
75
76 protected:
78 std::vector<std::string> hyperlinks_ = {""};
79
80 // The current selection style. This is overridden by various dom elements.
82 pixel.inverted ^= true;
83 };
84};
85
86} // namespace ftxui
87
88#endif // FTXUI_SCREEN_SCREEN_HPP
A rectangular grid of Pixel.
Definition image.hpp:17
int dimy() const
Definition image.hpp:33
int dimx() const
Definition image.hpp:32
A rectangular grid of Pixel.
Definition screen.hpp:27
std::function< void(Pixel &)> SelectionStyle
Definition screen.hpp:72
void ApplyShader()
Definition screen.cpp:500
const SelectionStyle & GetSelectionStyle() const
Return the current selection style.
Definition screen.cpp:549
std::string ToString() const
Definition screen.cpp:409
void SetCursor(Cursor cursor)
Definition screen.hpp:65
static Screen Create(Dimensions dimension)
Create a screen with the given dimension.
Definition screen.cpp:388
uint8_t RegisterHyperlink(const std::string &link)
Definition screen.cpp:527
Cursor cursor() const
Definition screen.hpp:64
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:469
Cursor cursor_
Definition screen.hpp:77
void Clear()
Clear all the pixel from the screen.
Definition screen.cpp:488
SelectionStyle selection_style_
Definition screen.hpp:81
void SetSelectionStyle(SelectionStyle decorator)
Set the current selection style.
Definition screen.cpp:555
std::vector< std::string > hyperlinks_
Definition screen.hpp:78
void Print() const
Definition screen.cpp:446
Dimensions Fixed(int)
Definition screen.cpp:369
Dimensions Full()
Definition screen.cpp:376
std::shared_ptr< T > Make(Args &&... args)
Definition component.hpp:26
A Unicode character and its associated style.
Definition pixel.hpp:15