2019-01-07 00:10:35 +08:00
|
|
|
#ifndef FTXUI_SCREEN_SCREEN
|
|
|
|
#define FTXUI_SCREEN_SCREEN
|
2018-10-10 01:06:03 +08:00
|
|
|
|
2020-03-24 04:26:00 +08:00
|
|
|
#include <memory>
|
2018-10-10 01:06:03 +08:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2019-01-20 05:06:05 +08:00
|
|
|
#include "ftxui/screen/box.hpp"
|
2020-03-24 04:26:00 +08:00
|
|
|
#include "ftxui/screen/color.hpp"
|
2018-10-12 15:23:37 +08:00
|
|
|
|
2019-01-12 22:00:08 +08:00
|
|
|
namespace ftxui {
|
2020-03-24 04:26:00 +08:00
|
|
|
class Node;
|
2018-10-10 01:06:03 +08:00
|
|
|
}
|
|
|
|
|
2019-01-12 22:00:08 +08:00
|
|
|
namespace ftxui {
|
2020-05-25 07:34:13 +08:00
|
|
|
using Element = std::shared_ptr<Node>;
|
2019-01-07 00:10:35 +08:00
|
|
|
|
2020-05-25 07:34:13 +08:00
|
|
|
/// @brief A unicode character and its associated style.
|
|
|
|
/// @ingroup screen
|
2018-10-10 01:06:03 +08:00
|
|
|
struct Pixel {
|
2018-10-12 15:23:37 +08:00
|
|
|
Color background_color = Color::Default;
|
|
|
|
Color foreground_color = Color::Default;
|
2021-06-13 02:33:02 +08:00
|
|
|
wchar_t character = U' ';
|
|
|
|
bool blink : 1;
|
|
|
|
bool bold : 1;
|
|
|
|
bool dim : 1;
|
|
|
|
bool inverted : 1;
|
|
|
|
bool underlined : 1;
|
|
|
|
|
|
|
|
Pixel()
|
|
|
|
: blink(false),
|
|
|
|
bold(false),
|
|
|
|
dim(false),
|
|
|
|
inverted(false),
|
|
|
|
underlined(false) {}
|
2018-10-10 01:06:03 +08:00
|
|
|
};
|
|
|
|
|
2020-05-25 07:34:13 +08:00
|
|
|
/// @brief Define how the Screen's dimensions should look like.
|
|
|
|
/// @ingroup screen
|
2019-01-27 04:52:55 +08:00
|
|
|
struct Dimension {
|
2020-05-25 07:34:13 +08:00
|
|
|
/// coucou
|
2019-01-27 04:52:55 +08:00
|
|
|
static Dimension Fixed(int);
|
2020-05-25 07:34:13 +08:00
|
|
|
/// @brief coucou
|
|
|
|
static Dimension Fit(Element&);
|
2019-01-27 04:52:55 +08:00
|
|
|
static Dimension Full();
|
|
|
|
|
|
|
|
int dimx;
|
|
|
|
int dimy;
|
|
|
|
};
|
|
|
|
|
2020-05-25 07:34:13 +08:00
|
|
|
/// @brief A rectangular grid of Pixel.
|
|
|
|
/// @ingroup screen
|
2018-10-10 01:06:03 +08:00
|
|
|
class Screen {
|
|
|
|
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(Dimension dimension);
|
|
|
|
static Screen Create(Dimension width, Dimension height);
|
2018-10-10 01:06:03 +08:00
|
|
|
|
2019-01-12 22:00:08 +08:00
|
|
|
// Node write into the screen using Screen::at.
|
2019-01-27 04:52:55 +08:00
|
|
|
wchar_t& at(int x, int y);
|
|
|
|
Pixel& PixelAt(int x, int y);
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
|
|
// Convert the screen into a printable string in the terminal.
|
|
|
|
std::string ToString();
|
2021-03-22 07:26:52 +08:00
|
|
|
void Print();
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
|
|
// Get screen dimensions.
|
2020-03-24 04:26:00 +08:00
|
|
|
int dimx() { return dimx_; }
|
|
|
|
int dimy() { return dimy_; }
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
|
|
// Move the terminal cursor n-lines up with n = dimy().
|
2021-05-17 06:44:37 +08:00
|
|
|
std::string ResetPosition(bool clear = false);
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
|
|
// Fill with space.
|
|
|
|
void Clear();
|
|
|
|
|
2019-01-19 07:20:29 +08:00
|
|
|
void ApplyShader();
|
2019-01-20 05:06:05 +08:00
|
|
|
Box stencil;
|
2019-01-19 07:20:29 +08:00
|
|
|
|
2019-06-30 00:52:58 +08:00
|
|
|
struct Cursor {
|
2019-07-01 06:43:00 +08:00
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
2019-06-30 00:52:58 +08:00
|
|
|
};
|
|
|
|
Cursor cursor() const { return cursor_; }
|
|
|
|
void SetCursor(Cursor cursor) { cursor_ = cursor; }
|
|
|
|
|
2019-01-05 09:03:49 +08:00
|
|
|
protected:
|
2019-01-27 04:52:55 +08:00
|
|
|
int dimx_;
|
|
|
|
int dimy_;
|
2018-10-10 01:06:03 +08:00
|
|
|
std::vector<std::vector<Pixel>> pixels_;
|
2019-06-30 00:52:58 +08:00
|
|
|
Cursor cursor_;
|
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
|
|
|
|
2019-01-07 00:10:35 +08:00
|
|
|
#endif /* end of include guard: FTXUI_SCREEN_SCREEN */
|
2020-08-16 06:24:18 +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.
|