FTXUI  5.0.0
C++ functional terminal UI.
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 <string> // for string, basic_string, allocator
9 #include <vector> // for vector
10 
11 #include "ftxui/screen/image.hpp" // for Pixel, Image
12 #include "ftxui/screen/terminal.hpp" // for Dimensions
13 
14 namespace ftxui {
15 
16 /// @brief Define how the Screen's dimensions should look like.
17 /// @ingroup screen
18 namespace Dimension {
19 Dimensions Fixed(int);
20 Dimensions Full();
21 } // namespace Dimension
22 
23 /// @brief A rectangular grid of Pixel.
24 /// @ingroup screen
25 class Screen : public Image {
26  public:
27  // Constructors:
28  Screen(int dimx, int dimy);
29  static Screen Create(Dimensions dimension);
30  static Screen Create(Dimensions width, Dimensions height);
31 
32  std::string ToString() const;
33 
34  // Print the Screen on to the terminal.
35  void Print() const;
36 
37  // Fill the screen with space and reset any screen state, like hyperlinks, and
38  // cursor
39  void Clear();
40 
41  // Move the terminal cursor n-lines up with n = dimy().
42  std::string ResetPosition(bool clear = false) const;
43 
44  void ApplyShader();
45 
46  struct Cursor {
47  int x = 0;
48  int y = 0;
49 
50  enum Shape {
51  Hidden = 0,
53  Block = 2,
55  Underline = 4,
57  Bar = 6,
58  };
60  };
61 
62  Cursor cursor() const { return cursor_; }
64 
65  // Store an hyperlink in the screen. Return the id of the hyperlink. The id is
66  // used to identify the hyperlink when the user click on it.
67  uint8_t RegisterHyperlink(const std::string& link);
68  const std::string& Hyperlink(uint8_t id) const;
69 
70  protected:
72  std::vector<std::string> hyperlinks_ = {""};
73 };
74 
75 } // namespace ftxui
76 
77 #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:25
void ApplyShader()
Definition: screen.cpp:500
const std::string & Hyperlink(uint8_t id) const
Definition: screen.cpp:540
std::string ToString() const
Definition: screen.cpp:409
void SetCursor(Cursor cursor)
Definition: screen.hpp:63
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
Screen(int dimx, int dimy)
Definition: screen.cpp:392
Cursor cursor() const
Definition: screen.hpp:62
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:71
void Clear()
Clear all the pixel from the screen.
Definition: screen.cpp:488
std::vector< std::string > hyperlinks_
Definition: screen.hpp:72
void Print() const
Definition: screen.cpp:446
Dimensions Fixed(int)
Definition: screen.cpp:369
Dimensions Full()
Definition: screen.cpp:376