libsshpp v0.1.7
Modern C++17 wrapper for libssh
Loading...
Searching...
No Matches
shell.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// Interactive shell sessions. See docs/design/05 ยง5.4. try_interact() (the
4// terminal raw-mode relay loop) is only declared/compiled when
5// LIBSSHPP_WITH_CONSOLE=ON, since it needs termios and installs a SIGWINCH
6// handler - a library embedded in a server has no business doing either.
7#pragma once
8
9#include <sshpp/config.hpp>
10
11#include <sshpp/channel.hpp>
12#include <sshpp/error.hpp>
13#include <sshpp/export.hpp>
14#include <sshpp/fwd.hpp>
15#include <sshpp/result.hpp>
16#include <sshpp/types.hpp>
17
18#include <chrono>
19#include <string>
20#include <string_view>
21#include <utility>
22#include <vector>
23
24namespace sshpp {
25
26#if SSHPP_WITH_CONSOLE
30struct InteractOptions {
31 bool enable_escape = true;
32 char escape_char = '~';
33};
34#endif
35
38class SSHPP_API Shell {
39public:
40 struct Options {
41 std::string term = "xterm-256color";
42 PtySize size{};
43 std::vector<std::pair<std::string, std::string>> env;
44 bool request_pty = true;
45 };
46
47 Shell(Session&, Options options);
48
49 Result<void> try_start();
50 Channel& channel() noexcept { return channel_; }
51
52 Result<std::size_t> try_write(std::string_view data);
53 Result<std::string> try_read(std::chrono::milliseconds timeout, Stream stream = Stream::stdout_);
54 Result<void> try_resize(PtySize);
55 Result<void> try_send_signal(Signal);
56
57#if SSHPP_WITH_CONSOLE
62 Result<ExitState> try_interact(InteractOptions options = {});
63#endif
64
65private:
66 Session* session_;
67 Options options_;
68 Channel channel_;
69};
70
71} // namespace sshpp
72
73#if SSHPP_HEADER_ONLY
75#endif
Definition channel.hpp:36
Definition result.hpp:16
Definition session.hpp:41
Definition shell.hpp:38
Channel & channel() noexcept
Definition shell.hpp:50
Definition auth.hpp:18
Signal
Definition channel.hpp:23
Stream
Definition channel.hpp:21
Definition channel.hpp:32
Definition shell.hpp:40
std::vector< std::pair< std::string, std::string > > env
Definition shell.hpp:43