FTXUI/include/ftxui/screen/screen.hpp

79 lines
2.0 KiB
C++
Raw Normal View History

2023-08-19 19:56:36 +08:00
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
2022-03-31 08:17:43 +08:00
#ifndef FTXUI_SCREEN_SCREEN_HPP
#define FTXUI_SCREEN_SCREEN_HPP
#include <cstdint> // for uint8_t
#include <memory>
#include <string> // for string, basic_string, allocator
2021-08-07 02:32:33 +08:00
#include <vector> // for vector
2021-08-07 02:32:33 +08:00
#include "ftxui/screen/color.hpp" // for Color, Color::Default
#include "ftxui/screen/image.hpp" // for Pixel, Image
2021-08-07 02:32:33 +08:00
#include "ftxui/screen/terminal.hpp" // for Dimensions
2018-10-12 15:23:37 +08:00
namespace ftxui {
2020-05-25 07:34:13 +08:00
/// @brief Define how the Screen's dimensions should look like.
/// @ingroup screen
namespace Dimension {
Dimensions Fixed(int);
Dimensions Full();
} // namespace Dimension
2019-01-27 04:52:55 +08:00
2020-05-25 07:34:13 +08:00
/// @brief A rectangular grid of Pixel.
/// @ingroup screen
class Screen : public Image {
public:
2020-05-25 07:34:13 +08:00
// Constructors:
2019-01-27 04:52:55 +08:00
Screen(int dimx, int dimy);
static Screen Create(Dimensions dimension);
static Screen Create(Dimensions width, Dimensions height);
std::string ToString() const;
// Print the Screen on to the terminal.
void Print() const;
// Fill the screen with space and reset any screen state, like hyperlinks, and cursor
void Clear();
// Move the terminal cursor n-lines up with n = dimy().
2022-03-31 08:17:43 +08:00
std::string ResetPosition(bool clear = false) const;
2019-01-19 07:20:29 +08:00
void ApplyShader();
struct Cursor {
2019-07-01 06:43:00 +08:00
int x = 0;
int y = 0;
enum Shape {
Hidden = 0,
BlockBlinking = 1,
Block = 2,
UnderlineBlinking = 3,
Underline = 4,
2022-12-28 20:17:56 +08:00
BarBlinking = 5,
Bar = 6,
};
Shape shape;
};
Cursor cursor() const { return cursor_; }
void SetCursor(Cursor cursor) { cursor_ = cursor; }
// Store an hyperlink in the screen. Return the id of the hyperlink. The id is
// used to identify the hyperlink when the user click on it.
uint8_t RegisterHyperlink(const std::string& link);
const std::string& Hyperlink(uint8_t id) const;
protected:
Cursor cursor_;
std::vector<std::string> hyperlinks_ = {""};
};
2020-02-12 04:44:55 +08:00
} // namespace ftxui
2022-03-31 08:17:43 +08:00
#endif // FTXUI_SCREEN_SCREEN_HPP