34 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT) 35 #error "Only <final/final.h> can be included directly." 43 #include <unordered_map> 47 #include "final/ftypes.h" 48 #include "final/util/frect.h" 49 #include "final/util/fstring.h" 70 auto getMappedChar (
wchar_t)
const noexcept -> wchar_t;
71 void setCharMapping (
const Map&) noexcept;
72 auto isEmpty()
const noexcept -> bool;
76 std::vector<Map> sub_map{};
81 inline FCharSubstitution::FCharSubstitution()
87 inline auto FCharSubstitution::getMappedChar (
wchar_t c)
const noexcept ->
wchar_t 89 auto iter = std::lower_bound ( sub_map.begin(), sub_map.end()
91 , [] (
const Map& map,
wchar_t value)
93 return map.from < value;
96 if ( iter == sub_map.end() || iter->from != c )
103 inline void FCharSubstitution::setCharMapping (
const Map& m) noexcept
105 auto iter = std::lower_bound ( sub_map.begin(), sub_map.end()
107 , [] (
const Map& map,
wchar_t value)
109 return map.from < value;
112 if ( iter != sub_map.end() && iter->from == m.from )
115 sub_map.insert(iter, m);
119 inline auto FCharSubstitution::isEmpty()
const noexcept ->
bool 121 return sub_map.empty();
125 inline void FCharSubstitution::sort()
127 std::sort ( sub_map.begin(), sub_map.end()
128 , [] (
const auto& lhs,
const auto& rhs)
130 return lhs.from < rhs.from;
150 using EncodingMap = std::unordered_map<std::string, Encoding>;
156 auto getClassName()
const ->
FString;
158 auto getEncodingList() & -> EncodingMap&;
160 auto getTerminalEncoding()
const -> Encoding;
161 auto getTerminalGeometry() & ->
FRect&;
162 auto getTerminalGeometry()
const & ->
const FRect&;
163 auto getTTYFileDescriptor()
const noexcept -> int;
164 auto getBaudrate()
const noexcept -> uInt;
165 auto getTermType()
const & ->
const std::string&;
166 auto getTermFileName()
const & ->
const std::string&;
167 auto getGnomeTerminalID()
const noexcept -> int;
169 auto getXtermFont()
const & ->
const FString&;
170 auto getXtermTitle()
const & ->
const FString&;
172 auto getFramebufferBpp()
const noexcept -> int;
176 auto hasShadowCharacter()
const noexcept -> bool;
177 auto hasHalfBlockCharacter()
const noexcept -> bool;
178 auto hasCursorOptimisation()
const noexcept -> bool;
179 auto isCursorHidden()
const noexcept -> bool;
180 auto hasAlternateScreen()
const noexcept -> bool;
181 auto isInAlternateScreen()
const noexcept -> bool;
182 auto hasASCIIConsole()
const noexcept -> bool;
183 auto hasVT100Console()
const noexcept -> bool;
184 auto hasUTF8Console()
const noexcept -> bool;
185 auto isUTF8()
const noexcept -> bool;
186 auto isNewFont()
const noexcept -> bool;
187 auto isVGAFont()
const noexcept -> bool;
188 auto isMonochron()
const noexcept -> bool;
189 auto hasTermResized() -> bool;
190 auto isTermType (FTermType)
const -> bool;
191 auto isTermType (FTermTypeT)
const -> bool;
194 void setTermEncoding (Encoding) noexcept;
195 void setTTYFileDescriptor (
int) noexcept;
196 void setBaudrate (uInt) noexcept;
197 void supportShadowCharacter (
bool =
true) noexcept;
198 void supportHalfBlockCharacter (
bool =
true) noexcept;
199 void supportCursorOptimisation (
bool =
true) noexcept;
200 void setCursorHidden (
bool =
true) noexcept;
201 void useAlternateScreen (
bool =
true) noexcept;
202 void setAlternateScreenInUse (
bool =
true) noexcept;
203 void setASCIIConsole (
bool =
true) noexcept;
204 void setVT100Console (
bool =
true) noexcept;
205 void setUTF8Console (
bool =
true) noexcept;
206 void setUTF8 (
bool =
true) noexcept;
207 void setNewFont (
bool =
true) noexcept;
208 void setVGAFont (
bool =
true) noexcept;
209 void setMonochron (
bool =
true) noexcept;
210 void setTermResized (
bool =
true);
211 void setTermType (
const std::string&);
212 void setTermType (FTermType);
213 void unsetTermType (FTermType);
214 void setTermFileName (
const std::string&);
215 void setGnomeTerminalID (
int) noexcept;
217 void setXtermFont (
const FString&);
218 void setXtermTitle (
const FString&);
220 void setFramebufferBpp (
int) noexcept;
227 EncodingMap encoding_list{};
229 Encoding term_encoding{Encoding::Unknown};
233 struct TerminalProperties
235 FRect terminal_geometry{};
238 FTermTypeT terminal_type{};
244 struct TerminalSettings
249 int gnome_terminal_id{0};
252 int framebuffer_bpp{-1};
255 std::string termtype{};
256 std::string term_file_name{};
260 struct SynchronizationState
262 std::mutex resize_mutex{};
263 std::atomic<int> resize_count{0};
268 bool shadow_character{
true};
269 bool half_block_character{
true};
270 bool cursor_optimisation{
true};
271 bool hidden_cursor{
false};
272 bool use_alternate_screen{
true};
273 bool alternate_screen{
false};
274 bool ascii_console{
false};
275 bool vt100_console{
false};
276 bool utf8_console{
false};
277 bool utf8_state{
false};
278 bool new_font{
false};
279 bool vga_font{
false};
280 bool monochron{
false};
284 EncodingInfo encoding_info{};
285 TerminalProperties terminal_properties{};
286 TerminalSettings terminal_settings{};
287 SynchronizationState synchronization_state{};
293 inline auto FTermData::getClassName()
const ->
FString 294 {
return "FTermData"; }
297 inline auto FTermData::getInstance() ->
FTermData&
299 static const auto& data = std::make_unique<FTermData>();
304 inline auto FTermData::getEncodingList() & -> EncodingMap&
305 {
return encoding_info.encoding_list; }
309 {
return encoding_info.char_substitution_map; }
312 inline auto FTermData::getTerminalEncoding()
const -> Encoding
313 {
return encoding_info.term_encoding; }
316 inline auto FTermData::getTerminalGeometry() & ->
FRect&
317 {
return terminal_properties.terminal_geometry; }
320 inline auto FTermData::getTerminalGeometry()
const & ->
const FRect&
321 {
return terminal_properties.terminal_geometry; }
324 inline auto FTermData::getTTYFileDescriptor()
const noexcept ->
int 325 {
return terminal_properties.fd_tty; }
328 inline auto FTermData::getBaudrate()
const noexcept -> uInt
329 {
return terminal_settings.baudrate; }
332 inline auto FTermData::getTermType()
const & ->
const std::string&
333 {
return terminal_settings.termtype; }
336 inline auto FTermData::getTermFileName()
const & ->
const std::string&
337 {
return terminal_settings.term_file_name; }
340 inline auto FTermData::getGnomeTerminalID()
const noexcept ->
int 341 {
return terminal_settings.gnome_terminal_id; }
344 inline auto FTermData::getKittyVersion()
const noexcept ->
kittyVersion 345 {
return terminal_settings.kitty_version; }
348 inline auto FTermData::getXtermFont()
const & ->
const FString&
349 {
return terminal_properties.xterm_font; }
352 inline auto FTermData::getXtermTitle()
const & ->
const FString&
353 {
return terminal_properties.xterm_title; }
357 inline auto FTermData::getFramebufferBpp()
const noexcept ->
int 358 {
return terminal_settings.framebuffer_bpp; }
362 inline auto FTermData::hasShadowCharacter()
const noexcept ->
bool 363 {
return flags.shadow_character; }
366 inline auto FTermData::hasHalfBlockCharacter()
const noexcept ->
bool 367 {
return flags.half_block_character; }
370 inline auto FTermData::hasCursorOptimisation()
const noexcept ->
bool 371 {
return flags.cursor_optimisation; }
374 inline auto FTermData::isCursorHidden()
const noexcept ->
bool 375 {
return flags.hidden_cursor; }
378 inline auto FTermData::hasAlternateScreen()
const noexcept ->
bool 379 {
return flags.use_alternate_screen; }
382 inline auto FTermData::isInAlternateScreen()
const noexcept ->
bool 383 {
return flags.alternate_screen; }
386 inline auto FTermData::hasASCIIConsole()
const noexcept ->
bool 387 {
return flags.ascii_console; }
390 inline auto FTermData::hasVT100Console()
const noexcept ->
bool 391 {
return flags.vt100_console; }
394 inline auto FTermData::hasUTF8Console()
const noexcept ->
bool 395 {
return flags.utf8_console; }
398 inline auto FTermData::isUTF8()
const noexcept ->
bool 399 {
return flags.utf8_state; }
402 inline auto FTermData::isNewFont()
const noexcept ->
bool 403 {
return flags.new_font; }
406 inline auto FTermData::isVGAFont()
const noexcept ->
bool 407 {
return flags.vga_font; }
410 inline auto FTermData::isMonochron()
const noexcept ->
bool 411 {
return flags.monochron; }
414 inline auto FTermData::hasTermResized() ->
bool 416 std::lock_guard<std::mutex> resize_lock_guard(synchronization_state.resize_mutex);
417 return synchronization_state.resize_count.load() > 0;
421 inline auto FTermData::isTermType (FTermType type)
const ->
bool 422 {
return terminal_properties.terminal_type &
static_cast<FTermTypeT
>(type); }
425 inline auto FTermData::isTermType (FTermTypeT mask)
const ->
bool 426 {
return terminal_properties.terminal_type & mask; }
429 inline void FTermData::setTermEncoding (Encoding enc) noexcept
430 { encoding_info.term_encoding = enc; }
433 inline void FTermData::setTTYFileDescriptor (
int fd) noexcept
434 { terminal_properties.fd_tty = fd; }
437 inline void FTermData::setBaudrate (uInt baud) noexcept
438 { terminal_settings.baudrate = baud; }
441 inline void FTermData::supportShadowCharacter (
bool available) noexcept
442 { flags.shadow_character = available; }
445 inline void FTermData::supportHalfBlockCharacter (
bool available) noexcept
446 { flags.half_block_character = available; }
449 inline void FTermData::supportCursorOptimisation (
bool available) noexcept
450 { flags.cursor_optimisation = available; }
453 inline void FTermData::setCursorHidden (
bool hidden_state) noexcept
454 { flags.hidden_cursor = hidden_state; }
457 inline void FTermData::useAlternateScreen (
bool use) noexcept
458 { flags.use_alternate_screen = use; }
461 inline void FTermData::setAlternateScreenInUse (
bool in_use) noexcept
462 { flags.alternate_screen = in_use; }
465 inline void FTermData::setASCIIConsole (
bool ascii) noexcept
466 { flags.ascii_console = ascii; }
469 inline void FTermData::setVT100Console (
bool vt100) noexcept
470 { flags.vt100_console = vt100; }
473 inline void FTermData::setUTF8Console (
bool utf8) noexcept
474 { flags.utf8_console = utf8; }
477 inline void FTermData::setUTF8 (
bool utf8) noexcept
478 { flags.utf8_state = utf8; }
481 inline void FTermData::setNewFont (
bool nfont) noexcept
482 { flags.new_font = nfont; }
485 inline void FTermData::setVGAFont (
bool vga) noexcept
486 { flags.vga_font = vga; }
489 inline void FTermData::setMonochron (
bool mono) noexcept
490 { flags.monochron = mono; }
493 inline void FTermData::setTermResized (
bool resize)
495 std::lock_guard<std::mutex> resize_lock_guard(synchronization_state.resize_mutex);
498 ++synchronization_state.resize_count;
499 else if ( synchronization_state.resize_count.load() > 0 )
500 --synchronization_state.resize_count;
504 inline void FTermData::setTermType (
const std::string& name)
506 if ( ! name.empty() )
507 terminal_settings.termtype = name;
511 inline void FTermData::setTermType (FTermType type)
512 { terminal_properties.terminal_type |=
static_cast<FTermTypeT
>(type); }
515 inline void FTermData::unsetTermType (FTermType type)
516 { terminal_properties.terminal_type &= ~(
static_cast<FTermTypeT
>(type)); }
519 inline void FTermData::setTermFileName (
const std::string& file_name)
521 if ( ! file_name.empty() )
522 terminal_settings.term_file_name = file_name;
526 inline void FTermData::setGnomeTerminalID (
int id) noexcept
527 { terminal_settings.gnome_terminal_id = id; }
530 inline void FTermData::setKittyVersion(
const kittyVersion& version)
532 terminal_settings.kitty_version.primary = version.primary;
533 terminal_settings.kitty_version.secondary = version.secondary;
537 inline void FTermData::setXtermFont (
const FString& font)
538 { terminal_properties.xterm_font = font; }
541 inline void FTermData::setXtermTitle (
const FString& title)
542 { terminal_properties.xterm_title = title; }
545 #if DEBUG && defined(__linux__) 546 inline void FTermData::setFramebufferBpp (
int bpp) noexcept
547 { terminal_settings.framebuffer_bpp = bpp; }
552 #endif // FTERMDATA_H Definition: ftermdata.h:61
Definition: ftermdata.h:58
Definition: class_template.cpp:25
Definition: ftermdata.h:143
Definition: ftermdata.h:140