PtySession class
#include <nxtio/subprocess.hpp>
Running child process connected to a PTY and a libvterm screen model.
Public types
-
using DamageCallback = std::
function<void()> - Called after input bytes from the PTY changed the terminal screen.
Public static functions
-
static auto shell(Size size,
std::
string shell_path = {}, std:: optional<std:: filesystem:: path> cwd = std:: nullopt) → PtySession - Spawn an interactive shell attached to a new PTY.
- static auto spawn(const SpawnOptions& options) → PtySession
- Spawn a child process attached to a new PTY.
Constructors, destructors, conversion operators
- PtySession(const PtySession&) deleted
- PtySession(PtySession&& other) noexcept
- ~PtySession()
Public functions
- auto child_pid() const → pid_t noexcept
- Child process id, or -1 after the session has been moved from.
- void close_master() noexcept
- Close the PTY master file descriptor.
-
auto encode_key(const nxt::
input:: KeyEvent& event) → std:: string - Convert a decoded input event into bytes for the child process.
-
auto exit_status() const → std::
optional<ExitStatus> - Last observed exit status, if the child has been reaped.
- auto master_fd() const → int noexcept
- PTY master file descriptor, or -1 when closed/moved.
- auto operator=(const PtySession&) → PtySession& deleted
- auto operator=(PtySession&& other) → PtySession& noexcept
-
auto read_loop(nxt::
scheduler& scheduler, std:: stop_token stop = {}, DamageCallback on_damage = {}) → nxt:: task<ExitStatus> - Read PTY output into libvterm until EOF, cancellation, or process exit.
- void resize(Size size)
- Resize both the kernel PTY and libvterm screen model.
- auto running() const → bool noexcept
- True while the child exists and has not been reaped.
-
auto send_key(nxt::
scheduler& scheduler, const nxt:: input:: KeyEvent& event, std:: stop_token stop = {}) → nxt:: task - Encode and send one input event to the child process.
-
auto terminal() → nxt::
vterm:: Terminal& noexcept - Terminal screen model owned by the session.
-
auto terminal() const → const nxt::
vterm:: Terminal& noexcept - Const terminal screen model owned by the session.
- void terminate(int signal = SIGHUP) noexcept
- Send a signal to the child process.
-
template <typename Fn>auto with_terminal(Fn&& fn) → decltype(auto)
- Run a function while holding the terminal mutex.
-
template <typename Fn>auto with_terminal(Fn&& fn) const → decltype(auto)
- Run a function while holding the terminal mutex.
-
void write(std::
string_view bytes) - Write bytes to the PTY master immediately.
-
auto write_all(nxt::
scheduler& scheduler, std:: string bytes, std:: stop_token stop = {}) → nxt:: task - Asynchronously write all bytes to the PTY master.