mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-28 16:29:34 +08:00
17
include/ftxui/screen/box.hpp
Normal file
17
include/ftxui/screen/box.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef FTXUI_SCREEN_BOX_HPP
|
||||
#define FTXUI_SCREEN_BOX_HPP
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
struct Box {
|
||||
int x_min;
|
||||
int x_max;
|
||||
int y_min;
|
||||
int y_max;
|
||||
|
||||
static Box Intersection(Box a, Box b);
|
||||
};
|
||||
|
||||
}; // namespace ftxui
|
||||
|
||||
#endif /* end of include guard: FTXUI_SCREEN_BOX_HPP */
|
40
include/ftxui/screen/color.hpp
Normal file
40
include/ftxui/screen/color.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#ifndef FTXUI_SCREEN_COLOR
|
||||
#define FTXUI_SCREEN_COLOR
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
enum class Color : uint8_t {
|
||||
// --- Transparent -----
|
||||
Default = 39,
|
||||
|
||||
// --- Grayscale -----
|
||||
Black = 30,
|
||||
GrayDark = 90,
|
||||
GrayLight = 37,
|
||||
White = 97,
|
||||
|
||||
// --- Hue -----
|
||||
Blue = 34,
|
||||
BlueLight = 94,
|
||||
|
||||
Cyan = 36,
|
||||
CyanLight = 96,
|
||||
|
||||
Green = 32,
|
||||
GreenLight = 92,
|
||||
|
||||
Magenta = 35,
|
||||
MagentaLight = 95,
|
||||
|
||||
Red = 31,
|
||||
RedLight = 91,
|
||||
|
||||
Yellow = 33,
|
||||
YellowLight = 93,
|
||||
};
|
||||
|
||||
}; // namespace ftxui
|
||||
|
||||
#endif /* end of include guard: FTXUI_COLOR_H_ */
|
72
include/ftxui/screen/screen.hpp
Normal file
72
include/ftxui/screen/screen.hpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#ifndef FTXUI_SCREEN_SCREEN
|
||||
#define FTXUI_SCREEN_SCREEN
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include "ftxui/screen/color.hpp"
|
||||
#include "ftxui/screen/box.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
class Node;
|
||||
}
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
struct Pixel {
|
||||
wchar_t character = U' ';
|
||||
bool blink = false;
|
||||
bool bold = false;
|
||||
bool dim = false;
|
||||
bool inverted = false;
|
||||
bool underlined = false;
|
||||
Color background_color = Color::Default;
|
||||
Color foreground_color = Color::Default;
|
||||
};
|
||||
|
||||
struct Dimension {
|
||||
static Dimension Fixed(int);
|
||||
static Dimension Fit(std::unique_ptr<Node>&);
|
||||
static Dimension Full();
|
||||
|
||||
int dimx;
|
||||
int dimy;
|
||||
};
|
||||
|
||||
class Screen {
|
||||
public:
|
||||
// Constructor.
|
||||
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.
|
||||
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();
|
||||
|
||||
void ApplyShader();
|
||||
Box stencil;
|
||||
|
||||
protected:
|
||||
int dimx_;
|
||||
int dimy_;
|
||||
std::vector<std::vector<Pixel>> pixels_;
|
||||
};
|
||||
|
||||
}; // namespace ftxui
|
||||
|
||||
#endif /* end of include guard: FTXUI_SCREEN_SCREEN */
|
9
include/ftxui/screen/string.hpp
Normal file
9
include/ftxui/screen/string.hpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <string>
|
||||
|
||||
std::string to_string(const std::wstring& s);
|
||||
std::wstring to_wstring(const std::string& s);
|
||||
|
||||
template<typename T>
|
||||
std::wstring to_wstring(T s) {
|
||||
return to_wstring(std::to_string(s));
|
||||
}
|
Reference in New Issue
Block a user