uvw  2.11.0
tty.h
1 #ifndef UVW_TTY_INCLUDE_H
2 #define UVW_TTY_INCLUDE_H
3 
4 
5 #include <type_traits>
6 #include <memory>
7 #include <uv.h>
8 #include "stream.h"
9 #include "util.h"
10 
11 
12 namespace uvw {
13 
14 
15 namespace details {
16 
17 
18 struct ResetModeMemo {
19  ~ResetModeMemo();
20 };
21 
22 
23 enum class UVTTYModeT: std::underlying_type_t<uv_tty_mode_t> {
24  NORMAL = UV_TTY_MODE_NORMAL,
25  RAW = UV_TTY_MODE_RAW,
26  IO = UV_TTY_MODE_IO
27 };
28 
29 
30 enum class UVTTYVTermStateT: std::underlying_type_t<uv_tty_vtermstate_t> {
31  SUPPORTED = UV_TTY_SUPPORTED,
32  UNSUPPORTED = UV_TTY_UNSUPPORTED
33 };
34 
35 
36 }
37 
38 
57 class TTYHandle final: public StreamHandle<TTYHandle, uv_tty_t> {
58  static std::shared_ptr<details::ResetModeMemo> resetModeMemo();
59 
60 public:
61  using Mode = details::UVTTYModeT;
62  using VTermState = details::UVTTYVTermStateT;
63 
64  explicit TTYHandle(ConstructorAccess ca, std::shared_ptr<Loop> ref, FileHandle desc, bool readable);
65 
70  bool init();
71 
88  bool mode(Mode m);
89 
94  bool reset() noexcept;
95 
101 
120  void vtermState(VTermState s) const noexcept;
121 
139  VTermState vtermState() const noexcept;
140 
141 private:
142  std::shared_ptr<details::ResetModeMemo> memo;
143  FileHandle::Type fd;
144  int rw;
145 };
146 
147 
148 }
149 
150 
151 #ifndef UVW_AS_LIB
152 #include "tty.cpp"
153 #endif
154 
155 #endif // UVW_TTY_INCLUDE_H
The StreamHandle handle.
Definition: stream.h:128
bool readable() const noexcept
Checks if the stream is readable.
Definition: stream.h:450
The TTYHandle handle.
Definition: tty.h:57
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:10
details::UVTypeWrapper< uv_file > FileHandle
Definition: util.h:189
Windows size representation.
Definition: util.h:180