mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-04 06:00:30 +00:00
b5d8549bb3
This is to make it possible, in the future, to create multiple instances of `NotCurses` for multiple terminals. The first instance of `NotCurses` becomes the default one, so that any instances of other classes that aren't explicitly created with a pointer to another `NotCurses` instance still work as expected. Note that currently trying to call `notcurses_init` twice results in the following error for me: 0x55555559bfc0 is already registered for signals Couldn't drop signals: 0x55555559bfc0 != 0x5555555b6720 terminate called after throwing an instance of 'ncpp::init_error*' Program received signal SIGABRT, Aborted. The error is signalled by `setup_signals` and the pointer shown in the message points to the first `struct notcurses` instance created.
73 lines
1.6 KiB
C++
73 lines
1.6 KiB
C++
#ifndef __NCPP_READER_HH
|
|
#define __NCPP_READER_HH
|
|
|
|
#include <notcurses/notcurses.h>
|
|
|
|
#include "NCAlign.hh"
|
|
#include "Plane.hh"
|
|
#include "Utilities.hh"
|
|
|
|
namespace ncpp
|
|
{
|
|
class NCPP_API_EXPORT Reader : public Root
|
|
{
|
|
public:
|
|
explicit Reader (Plane *p, int y, int x, const ncreader_options *opts)
|
|
: Reader (static_cast<const Plane*>(p), y, x, opts)
|
|
{}
|
|
|
|
explicit Reader (Plane const* p, int y, int x, const ncreader_options *opts)
|
|
: Root (Utilities::get_notcurses_cpp (p))
|
|
{
|
|
if (p == nullptr)
|
|
throw invalid_argument ("'plane' must be a valid pointer");
|
|
|
|
common_init (Utilities::to_ncplane (p), y, x, opts);
|
|
}
|
|
|
|
explicit Reader (Plane &p, int y, int x, const ncreader_options *opts)
|
|
: Reader (static_cast<Plane const&>(p), y, x, opts)
|
|
{}
|
|
|
|
explicit Reader (Plane const& p, int y, int x, const ncreader_options *opts)
|
|
: Root (Utilities::get_notcurses_cpp (p))
|
|
{
|
|
common_init (Utilities::to_ncplane (p), y, x, opts);
|
|
}
|
|
|
|
~Reader ()
|
|
{
|
|
if (!is_notcurses_stopped ())
|
|
ncreader_destroy (reader, nullptr);
|
|
}
|
|
|
|
bool clear () const NOEXCEPT_MAYBE
|
|
{
|
|
bool ret = ncreader_clear (reader) != 0;
|
|
return error_guard_cond<bool, bool> (ret, ret);
|
|
}
|
|
|
|
char* get_contents () const noexcept
|
|
{
|
|
return ncreader_contents(reader);
|
|
}
|
|
|
|
Plane* get_plane () const noexcept
|
|
{
|
|
return Plane::map_plane (ncreader_plane (reader));
|
|
}
|
|
|
|
private:
|
|
void common_init (ncplane *n, int y, int x, const ncreader_options *opts)
|
|
{
|
|
reader = ncreader_create (n, y, x, opts);
|
|
if (reader == nullptr)
|
|
throw init_error ("Notcurses failed to create a new reader");
|
|
}
|
|
|
|
private:
|
|
ncreader *reader;
|
|
};
|
|
}
|
|
#endif
|