FINAL CUT
ftermios.h
1 /***********************************************************************
2 * ftermios.h - Provides access to POSIX tty I/O control *
3 * *
4 * This file is part of the FINAL CUT widget toolkit *
5 * *
6 * Copyright 2018-2023 Markus Gans *
7 * *
8 * FINAL CUT is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as *
10 * published by the Free Software Foundation; either version 3 of *
11 * the License, or (at your option) any later version. *
12 * *
13 * FINAL CUT is distributed in the hope that it will be useful, but *
14 * WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this program. If not, see *
20 * <http://www.gnu.org/licenses/>. *
21 ***********************************************************************/
22 
23 /* Standalone class
24  * ════════════════
25  *
26  * ▕▔▔▔▔▔▔▔▔▔▔▏
27  * ▕ FTermios ▏
28  * ▕▁▁▁▁▁▁▁▁▁▁▏
29  */
30 
31 #ifndef FTERMIOS_H
32 #define FTERMIOS_H
33 
34 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
35  #error "Only <final/final.h> can be included directly."
36 #endif
37 
38 #include <termios.h>
39 #include <unistd.h>
40 
41 #include "final/ftypes.h"
42 #include "final/util/fstring.h"
43 
44 namespace finalcut
45 {
46 
47 //----------------------------------------------------------------------
48 // class FTermios
49 //----------------------------------------------------------------------
50 
51 class FTermios final
52 {
53  public:
54  // Constructors
55  FTermios();
56 
57  // Accessors
58  auto getClassName() const -> FString;
59  static auto getTTY() -> termios;
60  static auto getStdIn() noexcept -> int;
61  static auto getStdOut() noexcept -> int;
62  static auto getStdErr() noexcept -> int;
63 
64  // Inquiries
65  static auto isRaw() noexcept -> bool;
66 
67  // Methods
68  static void init();
69  static void setTTY (const termios&);
70  static void storeTTYsettings();
71  static void restoreTTYsettings();
72  static void setHardwareEcho();
73  static void unsetHardwareEcho();
74  static void setCaptureSendCharacters();
75  static void unsetCaptureSendCharacters();
76  static void setRawMode (bool = true);
77  static void unsetRawMode();
78  static void setCookedMode();
79  static auto getBaudRate() -> uInt;
80 
81  private:
82  // Data members
83  static int stdin_no;
84  static int stdout_no;
85  static int stderr_no;
86  static bool raw_mode;
87  static struct termios term_init;
88 };
89 
90 
91 // FTermios inline functions
92 //----------------------------------------------------------------------
93 inline auto FTermios::getClassName() const -> FString
94 { return "FTermios"; }
95 
96 //----------------------------------------------------------------------
97 inline auto FTermios::getStdIn() noexcept -> int
98 { return stdin_no; }
99 
100 //----------------------------------------------------------------------
101 inline auto FTermios::getStdOut() noexcept -> int
102 { return stdout_no; }
103 
104 //----------------------------------------------------------------------
105 inline auto FTermios::getStdErr() noexcept -> int
106 { return stderr_no; }
107 
108 //----------------------------------------------------------------------
109 inline auto FTermios::isRaw() noexcept -> bool
110 { return raw_mode; }
111 
112 //----------------------------------------------------------------------
113 inline void FTermios::unsetRawMode()
114 { setRawMode(false); }
115 
116 //----------------------------------------------------------------------
117 inline void FTermios::setCookedMode()
118 { setRawMode(false); }
119 
120 } // namespace finalcut
121 
122 #endif // FTERMIOS_H
Definition: ftermios.h:51
Definition: class_template.cpp:25
Definition: fstring.h:79