WPILibC++  2018.4.1-20180920141831-1187-gd2a5aaa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Tty.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #ifndef WPIUTIL_WPI_UV_TTY_H_
9 #define WPIUTIL_WPI_UV_TTY_H_
10 
11 #include <uv.h>
12 
13 #include <memory>
14 #include <utility>
15 
16 #include "wpi/uv/Stream.h"
17 
18 namespace wpi {
19 namespace uv {
20 
21 class Loop;
22 class Tty;
23 
28 class Tty final : public StreamImpl<Tty, uv_tty_t> {
29  struct private_init {};
30 
31  public:
32  explicit Tty(const private_init&) {}
33  ~Tty() noexcept override = default;
34 
43  static std::shared_ptr<Tty> Create(Loop& loop, uv_file fd, bool readable);
44 
53  static std::shared_ptr<Tty> Create(const std::shared_ptr<Loop>& loop,
54  uv_file fd, bool readable) {
55  return Create(*loop, fd, readable);
56  }
57 
63  void SetMode(uv_tty_mode_t mode) {
64  int err = uv_tty_set_mode(GetRaw(), mode);
65  if (err < 0) ReportError(err);
66  }
67 
72  void ResetMode() { Invoke(&uv_tty_reset_mode); }
73 
78  std::pair<int, int> GetWindowSize() {
79  int width = 0, height = 0;
80  Invoke(&uv_tty_get_winsize, GetRaw(), &width, &height);
81  return std::make_pair(width, height);
82  }
83 };
84 
85 } // namespace uv
86 } // namespace wpi
87 
88 #endif // WPIUTIL_WPI_UV_TTY_H_
static std::shared_ptr< Tty > Create(const std::shared_ptr< Loop > &loop, uv_file fd, bool readable)
Create a TTY handle.
Definition: Tty.h:53
std::pair< int, int > GetWindowSize()
Gets the current window size.
Definition: Tty.h:78
WPILib C++ utilities (wpiutil) namespace.
Definition: SmallString.h:21
TTY handle.
Definition: Tty.h:28
static std::shared_ptr< Tty > Create(Loop &loop, uv_file fd, bool readable)
Create a TTY handle.
uv_tty_t * GetRaw() const noexcept
Get the underlying handle data structure.
Definition: Stream.h:240
void ReportError(int err)
Report an error.
Definition: Handle.h:213
void SetMode(uv_tty_mode_t mode)
Set the TTY using the specified terminal mode.
Definition: Tty.h:63
Event loop.
Definition: Loop.h:37
void ResetMode()
Reset TTY settings to default values for the next process to take over.
Definition: Tty.h:72
Definition: Stream.h:225