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