FTXUI 7.0.0
C++ functional terminal UI.
Loading...
Searching...
No Matches
terminal.hpp
Go to the documentation of this file.
1// Copyright 2020 Arthur Sonzogni. All rights reserved.
2// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
4#ifndef FTXUI_SCREEN_TERMINAL_HPP
5#define FTXUI_SCREEN_TERMINAL_HPP
6
7#include <cstdint>
8
9#include <memory>
10#include <string_view>
11#include <vector>
12
13#include "ftxui/util/export.hpp"
14
15namespace ftxui {
16
17/// @brief Dimensions is a structure that represents the size of the terminal
18/// @ingroup screen
19struct FTXUI_EXPORT(SCREEN) Dimensions {
20 int dimx;
21 int dimy;
22};
23
24namespace Terminal {
25FTXUI_EXPORT(SCREEN) Dimensions Size();
26FTXUI_EXPORT(SCREEN) void SetFallbackSize(const Dimensions& fallbackSize);
27
28/// @brief Color is an enumeration that represents the color support of the
29/// terminal.
30/// @ingroup screen
37FTXUI_EXPORT(SCREEN) Color ColorSupport();
38FTXUI_EXPORT(SCREEN) void SetColorSupport(Color color);
39
40/// @brief Quirks is a structure that represents various terminal-specific
41/// behaviors that may require fallbacks.
42/// @ingroup screen
43class FTXUI_EXPORT(SCREEN) Quirks {
44 public:
45 Quirks();
46 ~Quirks();
47 Quirks(const Quirks&);
48 Quirks& operator=(const Quirks&);
49 Quirks(Quirks&&) noexcept;
50 Quirks& operator=(Quirks&&) noexcept;
51
52 /// @brief Whether the terminal font supports the 8 Unicode block characters.
53 bool BlockCharacters() const;
54 void SetBlockCharacters(bool v);
55
56 /// @brief Whether the terminal correctly handles hiding the cursor.
57 bool CursorHiding() const;
58 void SetCursorHiding(bool v);
59
60 /// @brief Whether the terminal should use ASCII characters for components.
61 bool ComponentAscii() const;
62 void SetComponentAscii(bool v);
63
64 /// @brief The level of color support of the terminal.
65 Color ColorSupport() const;
66 void SetColorSupport(Color v);
67
68 private:
69 struct Impl;
70 std::unique_ptr<Impl> impl_;
71};
72FTXUI_EXPORT(SCREEN) Quirks GetQuirks();
73FTXUI_EXPORT(SCREEN) void SetQuirks(const Quirks& quirks);
74
75/// @brief TerminalInfo is a structure that contains information about the
76/// terminal.
77/// @ingroup screen
78class FTXUI_EXPORT(SCREEN) TerminalInfo {
79 public:
80 TerminalInfo();
81 ~TerminalInfo();
82 TerminalInfo(const TerminalInfo&) = delete;
83 TerminalInfo& operator=(const TerminalInfo&) = delete;
84 TerminalInfo(TerminalInfo&&) noexcept;
85 TerminalInfo& operator=(TerminalInfo&&) noexcept;
86
87 void SetTerm(std::string_view term);
88 void SetColorterm(std::string_view colorterm);
89 void SetTermProgram(std::string_view term_program);
90 void SetTerminalName(std::string_view terminal_name);
91 void SetTerminalEmulatorName(std::string_view terminal_emulator_name);
92 void SetCapabilities(std::vector<int> capabilities);
93
94 Color ComputeColorSupport() const;
95
96 private:
97 struct Impl;
98 std::unique_ptr<Impl> impl_;
99};
100
101/// @brief Compute the color support based on environment variables and terminal
102/// identification.
103/// @param term The TERM environment variable.
104/// @param colorterm The COLORTERM environment variable.
105/// @param term_program The TERM_PROGRAM environment variable.
106/// @param terminal_name The terminal name (from DA2).
107/// @param terminal_emulator_name The terminal emulator name (from XTVERSION).
108/// @param capabilities The terminal capabilities (from DA1).
109FTXUI_EXPORT(SCREEN)
110Color ComputeColorSupport(std::string_view term,
111 std::string_view colorterm,
112 std::string_view term_program,
113 std::string_view terminal_name,
114 std::string_view terminal_emulator_name,
115 const std::vector<int>& capabilities);
116
117} // namespace Terminal
118
119} // namespace ftxui
120
121#endif // FTXUI_SCREEN_TERMINAL_HPP
#define FTXUI_EXPORT(component)
Definition export.hpp:24
Color
Color is an enumeration that represents the color support of the terminal.
Definition terminal.hpp:31
The FTXUI ftxui::Terminal:: namespace.
The FTXUI ftxui:: namespace.
Definition animation.hpp:11