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/surface.hpp" // for Surface
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 Cell.
25/// @ingroup screen
26class Screen : public Surface {
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 void ToString(std::string& ss) const;
38
39 // Print the Screen on to the terminal.
40 void Print() const;
41
42 // Fill the screen with space and reset any screen state, like hyperlinks, and
43 // cursor
44 void Clear();
45
46 // Move the terminal cursor n-lines up with n = dimy().
47 std::string ResetPosition(bool clear = false) const;
48 void ResetPosition(std::string& ss, bool clear = false) const;
49
50 void ApplyShader();
51
52 struct Cursor {
53 int x = 0;
54 int y = 0;
55
66 };
67
68 Cursor cursor() const { return cursor_; }
70
71 // Store an hyperlink in the screen. Return the id of the hyperlink. The id is
72 // used to identify the hyperlink when the user click on it.
73 uint8_t RegisterHyperlink(std::string_view link);
74 const std::string& Hyperlink(uint8_t id) const;
75
76 using SelectionStyle = std::function<void(Cell&)>;
77 const SelectionStyle& GetSelectionStyle() const;
78 void SetSelectionStyle(SelectionStyle decorator);
79
80 protected:
82 std::vector<std::string> hyperlinks_ = {""};
83
84 // The current selection style. This is overridden by various dom elements.
85 SelectionStyle selection_style_ = [](Cell& cell) { cell.inverted ^= true; };
86};
87
88} // namespace ftxui
89
90#endif // FTXUI_SCREEN_SCREEN_HPP
void ApplyShader()
Definition screen.cpp:537
const SelectionStyle & GetSelectionStyle() const
Return the current selection style.
Definition screen.cpp:586
const std::string & Hyperlink(uint8_t id) const
Definition screen.cpp:577
int dimy() const
Definition surface.hpp:40
std::string ToString() const
Definition screen.cpp:426
void SetCursor(Cursor cursor)
Definition screen.hpp:69
~Screen() override=default
uint8_t RegisterHyperlink(std::string_view link)
Definition screen.cpp:564
static Screen Create(Dimensions dimension)
Create a screen with the given dimension.
Definition screen.cpp:405
std::function< void(Cell &)> SelectionStyle
Definition screen.hpp:76
Screen(int dimx, int dimy)
Definition screen.cpp:409
Cursor cursor() const
Definition screen.hpp:68
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:497
Cursor cursor_
Definition screen.hpp:81
void Clear()
Clear all the cells from the screen.
Definition screen.cpp:525
SelectionStyle selection_style_
Definition screen.hpp:85
void SetSelectionStyle(SelectionStyle decorator)
Set the current selection style.
Definition screen.cpp:592
std::vector< std::string > hyperlinks_
Definition screen.hpp:82
void Print() const
Definition screen.cpp:474
int dimx() const
Definition surface.hpp:39
A rectangular grid of Cell.
Definition screen.hpp:26
A rectangular grid of Cell.
Definition surface.hpp:17
A Unicode character and its associated style.
Definition cell.hpp:15
Dimensions is a structure that represents the size of the terminal.
Definition terminal.hpp:11
The FTXUI ftxui::Dimension:: namespace.
Dimensions Fixed(int)
Dimensions Full()
The FTXUI ftxui:: namespace.
Definition animation.hpp:10