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 <memory>
9 #include <string> // for string, basic_string, allocator
10 #include <vector> // for vector
11 
12 #include "ftxui/screen/color.hpp" // for Color, Color::Default
13 #include "ftxui/screen/image.hpp" // for Pixel, Image
14 #include "ftxui/screen/terminal.hpp" // for Dimensions
15 
16 namespace ftxui {
17 
18 /// @brief Define how the Screen's dimensions should look like.
19 /// @ingroup screen
20 namespace Dimension {
21 Dimensions Fixed(int);
22 Dimensions Full();
23 } // namespace Dimension
24 
25 /// @brief A rectangular grid of Pixel.
26 /// @ingroup screen
27 class Screen : public Image {
28  public:
29  // Constructors:
30  Screen(int dimx, int dimy);
31  static Screen Create(Dimensions dimension);
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 cursor
40  void Clear();
41 
42  // Move the terminal cursor n-lines up with n = dimy().
43  std::string ResetPosition(bool clear = false) const;
44 
45  void ApplyShader();
46 
47  struct Cursor {
48  int x = 0;
49  int y = 0;
50 
51  enum Shape {
52  Hidden = 0,
54  Block = 2,
56  Underline = 4,
58  Bar = 6,
59  };
61  };
62 
63  Cursor cursor() const { return cursor_; }
65 
66  // Store an hyperlink in the screen. Return the id of the hyperlink. The id is
67  // used to identify the hyperlink when the user click on it.
68  uint8_t RegisterHyperlink(const std::string& link);
69  const std::string& Hyperlink(uint8_t id) const;
70 
71  protected:
73  std::vector<std::string> hyperlinks_ = {""};
74 };
75 
76 } // namespace ftxui
77 
78 #endif // FTXUI_SCREEN_SCREEN_HPP
A rectangular grid of Pixel.
Definition: image.hpp:19
int dimy() const
Definition: image.hpp:35
int dimx() const
Definition: image.hpp:34
A rectangular grid of Pixel.
Definition: screen.hpp:27
void ApplyShader()
Definition: screen.cpp:494
const std::string & Hyperlink(uint8_t id) const
Definition: screen.cpp:534
std::string ToString() const
Definition: screen.cpp:407
void SetCursor(Cursor cursor)
Definition: screen.hpp:64
static Screen Create(Dimensions dimension)
Create a screen with the given dimension.
Definition: screen.cpp:386
Screen(int dimx, int dimy)
Definition: screen.cpp:390
uint8_t RegisterHyperlink(const std::string &link)
Definition: screen.cpp:521
Cursor cursor() const
Definition: screen.hpp:63
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:463
Cursor cursor_
Definition: screen.hpp:72
void Clear()
Clear all the pixel from the screen.
Definition: screen.cpp:482
std::vector< std::string > hyperlinks_
Definition: screen.hpp:73
void Print() const
Definition: screen.cpp:440
Dimensions Fixed(int)
Definition: screen.cpp:367
Dimensions Full()
Definition: screen.cpp:374