Notcurses 3.0.13
a blingful library for TUIs and character graphics
Loading...
Searching...
No Matches
Subproc.hh
Go to the documentation of this file.
1#ifndef __NCPP_SUBPROC_HH
2#define __NCPP_SUBPROC_HH
3
5
6#include "Root.hh"
7#include "Plane.hh"
8#include "Widget.hh"
9#include "Utilities.hh"
10
11namespace ncpp
12{
14 {
15 public:
17
18 public:
19 explicit Subproc (Plane* plane, const char* bin, bool use_path = true,
20 char* const arg[] = nullptr, char* const env[] = nullptr,
21 ncfdplane_callback cbfxn = nullptr, ncfdplane_done_cb donecbfxn = nullptr)
22 : Subproc (plane, bin, nullptr, use_path, arg, env, cbfxn, donecbfxn)
23 {}
24
25 explicit Subproc (Plane* plane, const char* bin, const ncsubproc_options* opts, bool use_path = true,
26 char* const arg[] = nullptr, char* const env[] = nullptr,
27 ncfdplane_callback cbfxn = nullptr, ncfdplane_done_cb donecbfxn = nullptr)
28 : Widget (Utilities::get_notcurses_cpp (plane))
29 {
30 ensure_valid_plane (plane);
31 create_subproc (*plane, bin, opts, use_path, arg, env, cbfxn, donecbfxn);
32 take_plane_ownership (plane);
33 }
34
35 explicit Subproc (Plane& plane, const char* bin, bool use_path = true,
36 char* const arg[] = nullptr, char* const env[] = nullptr,
37 ncfdplane_callback cbfxn = nullptr, ncfdplane_done_cb donecbfxn = nullptr)
38 : Subproc (plane, bin, nullptr, use_path, arg, env, cbfxn, donecbfxn)
39 {}
40
41 explicit Subproc (Plane& plane, const char* bin, const ncsubproc_options* opts, bool use_path = true,
42 char* const arg[] = nullptr, char* const env[] = nullptr,
43 ncfdplane_callback cbfxn = nullptr, ncfdplane_done_cb donecbfxn = nullptr)
44 : Widget (Utilities::get_notcurses_cpp (plane))
45 {
46 ensure_valid_plane (plane);
47 create_subproc (plane, bin, opts, use_path, arg, env, cbfxn, donecbfxn);
48 take_plane_ownership (plane);
49 }
50
52 {
53 if (is_notcurses_stopped ())
54 return;
55
56 ncsubproc_destroy (subproc);
57 }
58
59 Plane* get_plane () const noexcept
60 {
61 return Plane::map_plane (ncsubproc_plane (subproc));
62 }
63
64 private:
65 void create_subproc (Plane& n, const char* bin, const ncsubproc_options* opts, bool use_path,
66 char* const arg[], char* const env[],
68 {
69 if (bin == nullptr)
70 throw invalid_argument ("'bin' must be a valid pointer");
71
72 if (opts == nullptr)
73 opts = &default_options;
74
75 if (use_path) {
76 if (env != nullptr) {
77 subproc = ncsubproc_createvpe (
78 n, opts, bin, arg, env, cbfxn, donecbfxn
79 );
80 } else {
81 subproc = ncsubproc_createvp (
82 n, opts, bin, arg, cbfxn, donecbfxn
83 );
84 }
85 } else {
86 subproc = ncsubproc_createv (
87 n, opts, bin, arg, cbfxn, donecbfxn
88 );
89 }
90
91 if (subproc == nullptr)
92 throw init_error ("Notcurses failed to create ncsubproc instance");
93 }
94
95 private:
96 ncsubproc *subproc;
97 };
98}
99#endif // __NCPP_SUBPROC_HH
#define NCPP_API_EXPORT
Definition _helpers.hh:9
static ncsubproc_options default_options
Definition Subproc.hh:16
Subproc(Plane *plane, const char *bin, bool use_path=true, char *const arg[]=nullptr, char *const env[]=nullptr, ncfdplane_callback cbfxn=nullptr, ncfdplane_done_cb donecbfxn=nullptr)
Definition Subproc.hh:19
Subproc(Plane &plane, const char *bin, const ncsubproc_options *opts, bool use_path=true, char *const arg[]=nullptr, char *const env[]=nullptr, ncfdplane_callback cbfxn=nullptr, ncfdplane_done_cb donecbfxn=nullptr)
Definition Subproc.hh:41
Subproc(Plane &plane, const char *bin, bool use_path=true, char *const arg[]=nullptr, char *const env[]=nullptr, ncfdplane_callback cbfxn=nullptr, ncfdplane_done_cb donecbfxn=nullptr)
Definition Subproc.hh:35
Subproc(Plane *plane, const char *bin, const ncsubproc_options *opts, bool use_path=true, char *const arg[]=nullptr, char *const env[]=nullptr, ncfdplane_callback cbfxn=nullptr, ncfdplane_done_cb donecbfxn=nullptr)
Definition Subproc.hh:25
Plane * get_plane() const noexcept
Definition Subproc.hh:59
ncsubproc * ncsubproc_createv(ncplane *n, const ncsubproc_options *opts, const char *bin, const char *const arg[], ncfdplane_callback cbfxn, ncfdplane_done_cb donecbfxn)
Definition fd.c:383
ncsubproc * ncsubproc_createvp(ncplane *n, const ncsubproc_options *opts, const char *bin, const char *const arg[], ncfdplane_callback cbfxn, ncfdplane_done_cb donecbfxn)
Definition fd.c:389
ncsubproc * ncsubproc_createvpe(ncplane *n, const ncsubproc_options *opts, const char *bin, const char *const arg[], const char *const env[], ncfdplane_callback cbfxn, ncfdplane_done_cb donecbfxn)
Definition fd.c:395
ncplane * ncsubproc_plane(ncsubproc *n)
Definition fd.c:449
int ncsubproc_destroy(ncsubproc *n)
Definition fd.c:402
const struct ncplane_options * opts
Definition notcurses.h:3483
vopts n
Definition notcurses.h:3502
int(* ncfdplane_done_cb)(struct ncfdplane *n, int fderrno, void *curry)
Definition notcurses.h:4547
int(* ncfdplane_callback)(struct ncfdplane *n, const void *buf, size_t s, void *curry)
Definition notcurses.h:4546