uvw  2.12.1
tty.h
1 #ifndef UVW_TTY_INCLUDE_H
2 #define UVW_TTY_INCLUDE_H
3 
4 #include <memory>
5 #include <type_traits>
6 #include <uv.h>
7 #include "stream.h"
8 #include "util.h"
9 
10 namespace uvw {
11 
12 namespace details {
13 
14 struct ResetModeMemo {
15  ~ResetModeMemo();
16 };
17 
18 enum class UVTTYModeT : std::underlying_type_t<uv_tty_mode_t> {
19  NORMAL = UV_TTY_MODE_NORMAL,
20  RAW = UV_TTY_MODE_RAW,
21  IO = UV_TTY_MODE_IO
22 };
23 
24 enum class UVTTYVTermStateT : std::underlying_type_t<uv_tty_vtermstate_t> {
25  SUPPORTED = UV_TTY_SUPPORTED,
26  UNSUPPORTED = UV_TTY_UNSUPPORTED
27 };
28 
29 } // namespace details
30 
49 class TTYHandle final: public StreamHandle<TTYHandle, uv_tty_t> {
50  static std::shared_ptr<details::ResetModeMemo> resetModeMemo();
51 
52 public:
53  using Mode = details::UVTTYModeT;
54  using VTermState = details::UVTTYVTermStateT;
55 
56  explicit TTYHandle(ConstructorAccess ca, std::shared_ptr<Loop> ref, FileHandle desc, bool readable);
57 
62  bool init();
63 
80  bool mode(Mode m);
81 
86  bool reset() noexcept;
87 
93 
112  void vtermState(VTermState s) const noexcept;
113 
131  VTermState vtermState() const noexcept;
132 
133 private:
134  std::shared_ptr<details::ResetModeMemo> memo;
135  FileHandle::Type fd;
136  int rw;
137 };
138 
139 } // namespace uvw
140 
141 #ifndef UVW_AS_LIB
142 # include "tty.cpp"
143 #endif
144 
145 #endif // UVW_TTY_INCLUDE_H
The StreamHandle handle.
Definition: stream.h:113
bool readable() const noexcept
Checks if the stream is readable.
Definition: stream.h:436
The TTYHandle handle.
Definition: tty.h:49
VTermState vtermState() const noexcept
Gets the current state of whether console virtual terminal sequences are handled by the library or th...
bool mode(Mode m)
Sets the TTY using the specified terminal mode.
WinSize getWinSize()
Gets the current Window size.
bool init()
Initializes the handle.
bool reset() noexcept
Resets TTY settings to default values.
uvw default namespace.
Definition: async.h:8
details::UVTypeWrapper< uv_file > FileHandle
Definition: util.h:204
Windows size representation.
Definition: util.h:196