Loading...
Searching...
No Matches
screen.hpp
Go to the documentation of this file.
// 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.
#ifndef FTXUI_SCREEN_SCREEN_HPP
#define FTXUI_SCREEN_SCREEN_HPP
#include <cstdint> // for uint8_t
#include <functional> // for function
#include <string> // for string, basic_string, allocator
#include <vector> // for vector
#include "ftxui/screen/image.hpp" // for Pixel, Image
#include "ftxui/screen/terminal.hpp" // for Dimensions
#include "ftxui/util/autoreset.hpp" // for AutoReset
namespace ftxui {
/// @brief Define how the Screen's dimensions should look like.
/// @ingroup screen
namespace Dimension {
Dimensions Fixed(int);
Dimensions Full();
} // namespace Dimension
/// @brief A rectangular grid of Pixel.
/// @ingroup screen
class Screen : public Image {
public:
// Constructors:
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().
std::string ResetPosition(bool clear = false) const;
void ApplyShader();
struct Cursor {
int x = 0;
int y = 0;
enum Shape {
Hidden = 0,
BlockBlinking = 1,
Block = 2,
UnderlineBlinking = 3,
Underline = 4,
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;
using SelectionStyle = std::function<void(Pixel&)>;
const SelectionStyle& GetSelectionStyle() const;
void SetSelectionStyle(SelectionStyle decorator);
protected:
Cursor cursor_;
std::vector<std::string> hyperlinks_ = {""};
// The current selection style. This is overridden by various dom elements.
SelectionStyle selection_style_ = [](Pixel& pixel) {
pixel.inverted ^= true;
};
};
} // namespace ftxui
#endif // FTXUI_SCREEN_SCREEN_HPP
autoreset.hpp
ftxui::Image::dimy
int dimy() const
Definition image.hpp:33
ftxui::Image::Image
Image()=delete
ftxui::Image::dimx
int dimx() const
Definition image.hpp:32
ftxui::Screen::SelectionStyle
std::function< void(Pixel &)> SelectionStyle
Definition screen.hpp:72
ftxui::Screen::ApplyShader
void ApplyShader()
Definition screen.cpp:506
ftxui::Screen::GetSelectionStyle
const SelectionStyle & GetSelectionStyle() const
Return the current selection style.
Definition screen.cpp:555
ftxui::Screen::Hyperlink
const std::string & Hyperlink(uint8_t id) const
Definition screen.cpp:546
ftxui::Screen::ToString
std::string ToString() const
Definition screen.cpp:415
ftxui::Screen::SetCursor
void SetCursor(Cursor cursor)
Definition screen.hpp:65
ftxui::Screen::Create
static Screen Create(Dimensions dimension)
Create a screen with the given dimension.
Definition screen.cpp:394
ftxui::Screen::RegisterHyperlink
uint8_t RegisterHyperlink(const std::string &link)
Definition screen.cpp:533
ftxui::Screen::Screen
Screen(int dimx, int dimy)
Definition screen.cpp:398
ftxui::Screen::cursor
Cursor cursor() const
Definition screen.hpp:64
ftxui::Screen::ResetPosition
std::string ResetPosition(bool clear=false) const
Return a string to be printed in order to reset the cursor position to the beginning of the screen.
Definition screen.cpp:475
ftxui::Screen::cursor_
Cursor cursor_
Definition screen.hpp:77
ftxui::Screen::Clear
void Clear()
Clear all the pixel from the screen.
Definition screen.cpp:494
ftxui::Screen::selection_style_
SelectionStyle selection_style_
Definition screen.hpp:81
ftxui::Screen::SetSelectionStyle
void SetSelectionStyle(SelectionStyle decorator)
Set the current selection style.
Definition screen.cpp:561
ftxui::Screen::hyperlinks_
std::vector< std::string > hyperlinks_
Definition screen.hpp:78
ftxui::Screen::Print
void Print() const
Definition screen.cpp:452
image.hpp
ftxui::Dimension
Define how the Screen's dimensions should look like.
Definition elements.hpp:191
ftxui::Dimension::Fixed
Dimensions Fixed(int)
Definition screen.cpp:375
ftxui::Dimension::Full
Dimensions Full()
Definition screen.cpp:382
ftxui
Definition animation.hpp:10
ftxui::Dimensions
Definition terminal.hpp:8
ftxui::Pixel
A Unicode character and its associated style.
Definition pixel.hpp:15
ftxui::Screen::Cursor
Definition screen.hpp:48
ftxui::Screen::Cursor::y
int y
Definition screen.hpp:50
ftxui::Screen::Cursor::Shape
Shape
Definition screen.hpp:52
ftxui::Screen::Cursor::BlockBlinking
@ BlockBlinking
Definition screen.hpp:54
ftxui::Screen::Cursor::Bar
@ Bar
Definition screen.hpp:59
ftxui::Screen::Cursor::Block
@ Block
Definition screen.hpp:55
ftxui::Screen::Cursor::Underline
@ Underline
Definition screen.hpp:57
ftxui::Screen::Cursor::Hidden
@ Hidden
Definition screen.hpp:53
ftxui::Screen::Cursor::UnderlineBlinking
@ UnderlineBlinking
Definition screen.hpp:56
ftxui::Screen::Cursor::BarBlinking
@ BarBlinking
Definition screen.hpp:58
ftxui::Screen::Cursor::x
int x
Definition screen.hpp:49
ftxui::Screen::Cursor::shape
Shape shape
Definition screen.hpp:61
terminal.hpp