Files
FTXUI/include/ftxui/screen/screen.hpp

94 lines
2.0 KiB
C++
Raw Normal View History

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