FTXUI 6.1.9
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
15namespace ftxui {
16
17/// @brief Define how the Screen's dimensions should look like.
18/// @ingroup screen
19namespace Dimension {
22} // namespace Dimension
23
24/// @brief A rectangular grid of Pixel.
25/// @ingroup screen
26class Screen : public Image {
27 public:
28 // Constructors:
29 Screen(int dimx, int dimy);
30 static Screen Create(Dimensions dimension);
31 static Screen Create(Dimensions width, Dimensions height);
32
33 // Destructor:
34 ~Screen() override = default;
35
36 std::string ToString() const;
37
38 // Print the Screen on to the terminal.
39 void Print() const;
40
41 // Fill the screen with space and reset any screen state, like hyperlinks, and
42 // cursor
43 void Clear();
44
45 // Move the terminal cursor n-lines up with n = dimy().
46 std::string ResetPosition(bool clear = false) const;
47
48 void ApplyShader();
49
50 struct Cursor {
51 int x = 0;
52 int y = 0;
53
64 };
65
66 Cursor cursor() const { return cursor_; }
68
69 // Store an hyperlink in the screen. Return the id of the hyperlink. The id is
70 // used to identify the hyperlink when the user click on it.
71 uint8_t RegisterHyperlink(const std::string& link);
72 const std::string& Hyperlink(uint8_t id) const;
73
74 using SelectionStyle = std::function<void(Pixel&)>;
75 const SelectionStyle& GetSelectionStyle() const;
76 void SetSelectionStyle(SelectionStyle decorator);
77
78 protected:
80 std::vector<std::string> hyperlinks_ = {""};
81
82 // The current selection style. This is overridden by various dom elements.
84 pixel.inverted ^= true;
85 };
86};
87
88} // namespace ftxui
89
90#endif // FTXUI_SCREEN_SCREEN_HPP
std::function< void(Pixel &)> SelectionStyle
Definition screen.hpp:74
void ApplyShader()
Definition screen.cpp:507
const SelectionStyle & GetSelectionStyle() const
Return the current selection style.
Definition screen.cpp:556
const std::string & Hyperlink(uint8_t id) const
Definition screen.cpp:547
int dimy() const
Definition image.hpp:36
std::string ToString() const
Definition screen.cpp:416
void SetCursor(Cursor cursor)
Definition screen.hpp:67
~Screen() override=default
static Screen Create(Dimensions dimension)
Create a screen with the given dimension.
Definition screen.cpp:395
uint8_t RegisterHyperlink(const std::string &link)
Definition screen.cpp:534
Screen(int dimx, int dimy)
Definition screen.cpp:399
Cursor cursor() const
Definition screen.hpp:66
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:476
Cursor cursor_
Definition screen.hpp:79
void Clear()
Clear all the pixel from the screen.
Definition screen.cpp:495
SelectionStyle selection_style_
Definition screen.hpp:83
void SetSelectionStyle(SelectionStyle decorator)
Set the current selection style.
Definition screen.cpp:562
std::vector< std::string > hyperlinks_
Definition screen.hpp:80
void Print() const
Definition screen.cpp:453
int dimx() const
Definition image.hpp:35
A rectangular grid of Pixel.
Definition image.hpp:17
A rectangular grid of Pixel.
Definition screen.hpp:26
Dimensions is a structure that represents the size of the terminal.
Definition terminal.hpp:11
A Unicode character and its associated style.
Definition pixel.hpp:15
Dimensions Fixed(int)
Dimensions Full()
The FTXUI ftxui:: namespace.
Definition animation.hpp:10