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
|
2018-10-10 01:06:03 +08:00
|
|
|
|
2023-06-05 03:06:19 +08:00
|
|
|
#include <cstdint> // for uint8_t
|
2024-05-01 17:40:49 +08:00
|
|
|
#include <string> // for string, basic_string, allocator
|
|
|
|
#include <vector> // for vector
|
2018-10-10 01:06:03 +08:00
|
|
|
|
2024-04-27 17:03:44 +08:00
|
|
|
#include "ftxui/screen/image.hpp" // for Pixel, Image
|
2021-08-07 02:32:33 +08:00
|
|
|
#include "ftxui/screen/terminal.hpp" // for Dimensions
|
2024-10-31 21:57:45 +08:00
|
|
|
#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse
|
2018-10-12 15:23:37 +08:00
|
|
|
|
2019-01-12 22:00:08 +08:00
|
|
|
namespace ftxui {
|
2019-01-07 00:10:35 +08:00
|
|
|
|
2020-05-25 07:34:13 +08:00
|
|
|
/// @brief Define how the Screen's dimensions should look like.
|
|
|
|
/// @ingroup screen
|
2021-08-03 05:19:29 +08:00
|
|
|
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
|
2024-04-27 17:03:44 +08:00
|
|
|
class Screen : public Image {
|
2018-10-10 01:06:03 +08:00
|
|
|
public:
|
2020-05-25 07:34:13 +08:00
|
|
|
// Constructors:
|
2019-01-27 04:52:55 +08:00
|
|
|
Screen(int dimx, int dimy);
|
2021-08-03 05:19:29 +08:00
|
|
|
static Screen Create(Dimensions dimension);
|
|
|
|
static Screen Create(Dimensions width, Dimensions height);
|
2018-10-10 01:06:03 +08:00
|
|
|
|
2023-07-26 06:41:16 +08:00
|
|
|
std::string ToString() const;
|
2018-10-10 01:06:03 +08:00
|
|
|
|
2023-07-26 06:41:16 +08:00
|
|
|
// Print the Screen on to the terminal.
|
|
|
|
void Print() const;
|
2018-10-10 01:06:03 +08:00
|
|
|
|
2024-04-28 21:17:54 +08:00
|
|
|
// Fill the screen with space and reset any screen state, like hyperlinks, and
|
|
|
|
// cursor
|
2024-04-27 17:03:44 +08:00
|
|
|
void Clear();
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
|
|
// 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;
|
2018-10-10 01:06:03 +08:00
|
|
|
|
2019-01-19 07:20:29 +08:00
|
|
|
void ApplyShader();
|
|
|
|
|
2019-06-30 00:52:58 +08:00
|
|
|
struct Cursor {
|
2019-07-01 06:43:00 +08:00
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
2022-11-11 21:09:53 +08:00
|
|
|
|
|
|
|
enum Shape {
|
|
|
|
Hidden = 0,
|
|
|
|
BlockBlinking = 1,
|
|
|
|
Block = 2,
|
|
|
|
UnderlineBlinking = 3,
|
|
|
|
Underline = 4,
|
2022-12-28 20:17:56 +08:00
|
|
|
BarBlinking = 5,
|
|
|
|
Bar = 6,
|
2022-11-11 21:09:53 +08:00
|
|
|
};
|
|
|
|
Shape shape;
|
2019-06-30 00:52:58 +08:00
|
|
|
};
|
2024-04-27 17:03:44 +08:00
|
|
|
|
2019-06-30 00:52:58 +08:00
|
|
|
Cursor cursor() const { return cursor_; }
|
|
|
|
void SetCursor(Cursor cursor) { cursor_ = cursor; }
|
|
|
|
|
2024-10-31 21:57:45 +08:00
|
|
|
bool selection_enabled = false;
|
|
|
|
CapturedMouse selection_pending;
|
|
|
|
Box selection_region;
|
|
|
|
std::string selection_text;
|
|
|
|
|
2023-06-05 03:06:19 +08:00
|
|
|
// 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.
|
2023-06-25 23:22:05 +08:00
|
|
|
uint8_t RegisterHyperlink(const std::string& link);
|
2023-06-05 03:06:19 +08:00
|
|
|
const std::string& Hyperlink(uint8_t id) const;
|
|
|
|
|
2019-01-05 09:03:49 +08:00
|
|
|
protected:
|
2019-06-30 00:52:58 +08:00
|
|
|
Cursor cursor_;
|
2023-06-05 03:06:19 +08:00
|
|
|
std::vector<std::string> hyperlinks_ = {""};
|
2018-10-10 01:06:03 +08:00
|
|
|
};
|
|
|
|
|
2020-02-12 04:44:55 +08:00
|
|
|
} // namespace ftxui
|
2018-10-10 01:06:03 +08:00
|
|
|
|
2022-03-31 08:17:43 +08:00
|
|
|
#endif // FTXUI_SCREEN_SCREEN_HPP
|