Notcurses 3.0.13
a blingful library for TUIs and character graphics
Loading...
Searching...
No Matches
Reader.hh
Go to the documentation of this file.
1#ifndef __NCPP_READER_HH
2#define __NCPP_READER_HH
3
5
6#include "NCAlign.hh"
7#include "Plane.hh"
8#include "Utilities.hh"
9#include "Widget.hh"
10
11namespace ncpp
12{
14 {
15 public:
16 explicit Reader (Plane *plane, const ncreader_options *opts)
17 : Widget (Utilities::get_notcurses_cpp (plane))
18 {
19 ensure_valid_plane (plane);
20 common_init (Utilities::to_ncplane (plane), opts);
21 take_plane_ownership (plane);
22 }
23
24 explicit Reader (Plane &plane, const ncreader_options *opts)
25 : Widget (Utilities::get_notcurses_cpp (plane))
26 {
27 ensure_valid_plane (plane);
28 common_init (Utilities::to_ncplane (plane), opts);
29 take_plane_ownership (plane);
30 }
31
33 {
34 if (!is_notcurses_stopped ())
35 ncreader_destroy (reader, nullptr);
36 }
37
38 bool clear () const NOEXCEPT_MAYBE
39 {
40 bool ret = ncreader_clear (reader) != 0;
41 return error_guard_cond<bool, bool> (ret, ret);
42 }
43
44 //
45 // None of the move* methods should throw since their return value (0 - moved, -1 - not moved) appear to be
46 // purely informational, not errors per se. If we had `can_move*` functions then `move*` could throw exceptions,
47 // potentially.
48 //
49 int move_left () const noexcept
50 {
51 return ncreader_move_left (reader);
52 }
53
54 int move_right () const noexcept
55 {
56 return ncreader_move_right (reader);
57 }
58
59 int move_up () const noexcept
60 {
61 return ncreader_move_up (reader);
62 }
63
64 int move_down () const noexcept
65 {
66 return ncreader_move_down (reader);
67 }
68
69 bool write_egc (const char *egc) const NOEXCEPT_MAYBE
70 {
71 return error_guard (ncreader_write_egc (reader, egc), -1);
72 }
73
74 char* get_contents () const noexcept
75 {
76 return ncreader_contents(reader);
77 }
78
79 Plane* get_plane () const noexcept
80 {
81 return Plane::map_plane (ncreader_plane (reader));
82 }
83
84 private:
85 void common_init (ncplane *n, const ncreader_options *opts)
86 {
87 reader = ncreader_create (n, opts);
88 if (reader == nullptr)
89 throw init_error ("Notcurses failed to create a new reader");
90 }
91
92 private:
93 ncreader *reader;
94 };
95}
96#endif
#define NCPP_API_EXPORT
Definition _helpers.hh:9
#define NOEXCEPT_MAYBE
Definition Root.hh:15
int move_down() const noexcept
Definition Reader.hh:64
int move_left() const noexcept
Definition Reader.hh:49
bool write_egc(const char *egc) const NOEXCEPT_MAYBE
Definition Reader.hh:69
bool clear() const NOEXCEPT_MAYBE
Definition Reader.hh:38
int move_right() const noexcept
Definition Reader.hh:54
Reader(Plane &plane, const ncreader_options *opts)
Definition Reader.hh:24
Reader(Plane *plane, const ncreader_options *opts)
Definition Reader.hh:16
char * get_contents() const noexcept
Definition Reader.hh:74
int move_up() const noexcept
Definition Reader.hh:59
Plane * get_plane() const noexcept
Definition Reader.hh:79
const char * egc
Definition egcpool.h:173
const struct ncplane_options * opts
Definition notcurses.h:3483
vopts n
Definition notcurses.h:3502
int ncreader_move_up(ncreader *n)
Definition reader.c:187
int ncreader_move_down(ncreader *n)
Definition reader.c:202
ncreader * ncreader_create(ncplane *n, const ncreader_options *opts)
Definition reader.c:26
int ncreader_write_egc(ncreader *n, const char *egc)
Definition reader.c:216
char * ncreader_contents(const ncreader *n)
Definition reader.c:413
void ncreader_destroy(ncreader *n, char **contents)
Definition reader.c:17
ncplane * ncreader_plane(ncreader *n)
Definition reader.c:80
int ncreader_clear(ncreader *n)
Definition reader.c:73
int ncreader_move_right(ncreader *n)
Definition reader.c:152
int ncreader_move_left(ncreader *n)
Definition reader.c:115