2020-01-07 22:51:34 +00:00
|
|
|
#ifndef __NCPP_NOTCURSES_HH
|
|
|
|
#define __NCPP_NOTCURSES_HH
|
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
#include <ctime>
|
|
|
|
#include <csignal>
|
|
|
|
#include <mutex>
|
|
|
|
|
2020-02-18 17:36:16 +00:00
|
|
|
#include <notcurses/notcurses.h>
|
2020-01-07 22:51:34 +00:00
|
|
|
|
|
|
|
#include "CellStyle.hh"
|
|
|
|
#include "NCKey.hh"
|
|
|
|
#include "NCLogLevel.hh"
|
|
|
|
#include "Palette256.hh"
|
|
|
|
#include "Plane.hh"
|
|
|
|
#include "Root.hh"
|
|
|
|
#include "_helpers.hh"
|
|
|
|
|
|
|
|
namespace ncpp
|
|
|
|
{
|
|
|
|
class NCPP_API_EXPORT NotCurses : public Root
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static notcurses_options default_notcurses_options;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit NotCurses (FILE *fp = nullptr)
|
|
|
|
: NotCurses (default_notcurses_options, fp)
|
|
|
|
{}
|
|
|
|
|
|
|
|
explicit NotCurses (const notcurses_options &nc_opts, FILE *fp = nullptr);
|
|
|
|
|
|
|
|
// Must not move or copy a NotCurses instance because we have no way to guarantee validity of any other copy
|
2020-01-25 17:45:35 +00:00
|
|
|
// when even a single instance is destructed as that operation would close notcurses.
|
2020-01-07 22:51:34 +00:00
|
|
|
NotCurses (const NotCurses &other) = delete;
|
|
|
|
NotCurses (NotCurses &&other) = delete;
|
2020-01-25 17:45:35 +00:00
|
|
|
~NotCurses ();
|
2020-01-07 22:51:34 +00:00
|
|
|
|
2020-05-09 01:01:22 +00:00
|
|
|
operator notcurses* () noexcept
|
|
|
|
{
|
|
|
|
return nc;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator notcurses const* () const noexcept
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
|
|
|
return nc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NotCurses& get_instance ()
|
|
|
|
{
|
|
|
|
if (_instance == nullptr)
|
2020-02-16 19:25:26 +00:00
|
|
|
throw invalid_state_error ("NotCurses instance not found.");
|
2020-01-07 22:51:34 +00:00
|
|
|
if (_instance->nc == nullptr)
|
2020-02-16 19:25:26 +00:00
|
|
|
throw invalid_state_error (ncpp_invalid_state_message);
|
2020-01-07 22:51:34 +00:00
|
|
|
|
|
|
|
return *_instance;
|
|
|
|
}
|
|
|
|
|
2020-05-24 12:41:18 +00:00
|
|
|
static bool is_notcurses_stopped (const NotCurses *ncinst = nullptr)
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2020-05-24 12:41:18 +00:00
|
|
|
if (ncinst != nullptr)
|
|
|
|
return ncinst->nc == nullptr;
|
|
|
|
|
2020-05-09 01:01:22 +00:00
|
|
|
return *_instance == nullptr || _instance->nc == nullptr;
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 06:14:27 +00:00
|
|
|
static const char* ncmetric (uintmax_t val, uintmax_t decimal, char *buf, int omitdec, unsigned mult, int uprefix) noexcept
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2020-02-06 01:18:11 +00:00
|
|
|
return ::ncmetric (val, decimal, buf, omitdec, mult, uprefix);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 06:14:27 +00:00
|
|
|
static const char* qprefix (uintmax_t val, uintmax_t decimal, char *buf, int omitdec) noexcept
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
|
|
|
return ::qprefix (val, decimal, buf, omitdec);
|
|
|
|
}
|
|
|
|
|
2020-05-17 06:14:27 +00:00
|
|
|
static const char* bprefix (uintmax_t val, uintmax_t decimal, char *buf, int omitdec) noexcept
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
|
|
|
return ::bprefix (val, decimal, buf, omitdec);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* version () noexcept
|
|
|
|
{
|
|
|
|
return notcurses_version ();
|
|
|
|
}
|
|
|
|
|
2020-07-31 20:59:59 +00:00
|
|
|
static void version_components (int* major, int* minor, int* patch, int* tweak) noexcept
|
|
|
|
{
|
|
|
|
notcurses_version_components (major, minor, patch, tweak);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* str_blitter (ncblitter_e blitter) noexcept
|
|
|
|
{
|
|
|
|
return notcurses_str_blitter (blitter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* str_scalemode (ncscale_e scalemode) noexcept
|
|
|
|
{
|
|
|
|
return notcurses_str_scalemode (scalemode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool lex_margins (const char* op, notcurses_options* opts) NOEXCEPT_MAYBE
|
|
|
|
{
|
|
|
|
return error_guard (notcurses_lex_margins (op, opts), -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool lex_blitter (const char* op, ncblitter_e* blitter) NOEXCEPT_MAYBE
|
|
|
|
{
|
|
|
|
return error_guard (notcurses_lex_blitter (op, blitter), -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool lex_scalemode (const char* op, ncscale_e* scalemode) NOEXCEPT_MAYBE
|
|
|
|
{
|
|
|
|
return error_guard (notcurses_lex_scalemode (op, scalemode), -1);
|
|
|
|
}
|
|
|
|
|
2020-05-22 07:31:03 +00:00
|
|
|
bool stop ();
|
2020-01-07 22:51:34 +00:00
|
|
|
|
2020-05-24 08:07:12 +00:00
|
|
|
bool can_utf8 () const noexcept
|
|
|
|
{
|
|
|
|
return notcurses_canutf8 (nc);
|
|
|
|
}
|
|
|
|
|
2020-01-07 22:51:34 +00:00
|
|
|
bool can_fade () const noexcept
|
|
|
|
{
|
|
|
|
return notcurses_canfade (nc);
|
|
|
|
}
|
|
|
|
|
2020-05-13 00:10:53 +00:00
|
|
|
bool can_open_images () const noexcept
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2020-05-13 00:10:53 +00:00
|
|
|
return notcurses_canopen_images (nc);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool can_open_videos () const noexcept
|
|
|
|
{
|
|
|
|
return notcurses_canopen_videos (nc);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool can_change_color () const noexcept
|
|
|
|
{
|
|
|
|
return notcurses_canchangecolor (nc);
|
|
|
|
}
|
|
|
|
|
2020-06-22 19:49:13 +00:00
|
|
|
bool can_truecolor () const noexcept
|
|
|
|
{
|
|
|
|
return notcurses_cantruecolor (nc);
|
|
|
|
}
|
|
|
|
|
2020-01-07 22:51:34 +00:00
|
|
|
void get_stats (ncstats *stats) const noexcept
|
|
|
|
{
|
|
|
|
if (stats == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
notcurses_stats (nc, stats);
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset_stats (ncstats *stats) const
|
|
|
|
{
|
|
|
|
if (stats == nullptr)
|
2020-02-16 19:25:26 +00:00
|
|
|
throw invalid_argument ("'stats' must be a valid pointer");
|
2020-01-07 22:51:34 +00:00
|
|
|
|
|
|
|
notcurses_reset_stats (nc, stats);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool use (const Palette256 *p) const
|
|
|
|
{
|
|
|
|
if (p == nullptr)
|
2020-02-16 19:25:26 +00:00
|
|
|
throw invalid_argument ("'p' must be a valid pointer");
|
2020-01-07 22:51:34 +00:00
|
|
|
|
|
|
|
return use (*p);
|
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
bool use (const Palette256 &p) const NOEXCEPT_MAYBE
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2020-04-12 21:09:03 +00:00
|
|
|
return error_guard (palette256_use (nc, reinterpret_cast<const palette256*>(&p)), -1);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
2020-04-18 18:57:52 +00:00
|
|
|
bool render () const NOEXCEPT_MAYBE
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2020-04-18 18:57:52 +00:00
|
|
|
return error_guard (notcurses_render (nc), -1);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
2020-07-31 20:59:59 +00:00
|
|
|
bool render_to_file (FILE* fp) const NOEXCEPT_MAYBE
|
|
|
|
{
|
|
|
|
return error_guard (notcurses_render_to_file (nc, fp), -1);
|
|
|
|
}
|
|
|
|
|
2020-01-07 22:51:34 +00:00
|
|
|
void get_term_dim (int *rows, int *cols) const noexcept
|
|
|
|
{
|
|
|
|
notcurses_term_dim_yx (nc, rows, cols);
|
|
|
|
}
|
|
|
|
|
|
|
|
void get_term_dim (int &rows, int &cols) const noexcept
|
|
|
|
{
|
|
|
|
get_term_dim (&rows, &cols);
|
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
bool refresh (int* rows, int* cols) const NOEXCEPT_MAYBE
|
2020-04-08 09:39:41 +00:00
|
|
|
{
|
2020-04-12 21:09:03 +00:00
|
|
|
return error_guard (notcurses_refresh (nc, rows, cols), -1);
|
2020-04-08 09:39:41 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
bool refresh (int& rows, int& cols) const NOEXCEPT_MAYBE
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2020-04-12 21:09:03 +00:00
|
|
|
return refresh (&rows, &cols);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
2020-08-16 04:27:27 +00:00
|
|
|
unsigned get_palette_size () const noexcept
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
|
|
|
return notcurses_palette_size (static_cast<const notcurses*> (nc));
|
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
bool mouse_enable () const NOEXCEPT_MAYBE
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2020-04-12 21:09:03 +00:00
|
|
|
return error_guard (notcurses_mouse_enable (nc), -1);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
bool mouse_disable () const NOEXCEPT_MAYBE
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2020-04-12 21:09:03 +00:00
|
|
|
return error_guard (notcurses_mouse_disable (nc), -1);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CellStyle get_supported_styles () const noexcept
|
|
|
|
{
|
|
|
|
return static_cast<CellStyle>(notcurses_supported_styles (nc));
|
|
|
|
}
|
|
|
|
|
|
|
|
char32_t getc (const timespec *ts, sigset_t *sigmask = nullptr, ncinput *ni = nullptr) const noexcept
|
|
|
|
{
|
|
|
|
return notcurses_getc (nc, ts, sigmask, ni);
|
|
|
|
}
|
|
|
|
|
|
|
|
char32_t getc (bool blocking = false, ncinput *ni = nullptr) const noexcept
|
|
|
|
{
|
|
|
|
if (blocking)
|
|
|
|
return notcurses_getc_blocking (nc, ni);
|
|
|
|
|
|
|
|
return notcurses_getc_nblock (nc, ni);
|
|
|
|
}
|
|
|
|
|
2020-08-15 23:25:08 +00:00
|
|
|
char* get_at (int yoff, int xoff, uint16_t* attr, uint64_t* channels) const noexcept
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2020-03-27 07:49:13 +00:00
|
|
|
return notcurses_at_yx (nc, yoff, xoff, attr, channels);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 21:01:21 +00:00
|
|
|
int get_inputready_fd () const noexcept
|
|
|
|
{
|
|
|
|
return notcurses_inputready_fd (nc);
|
|
|
|
}
|
|
|
|
|
2020-02-16 19:25:26 +00:00
|
|
|
void drop_planes () const noexcept
|
|
|
|
{
|
|
|
|
notcurses_drop_planes (nc);
|
|
|
|
}
|
|
|
|
|
2020-05-24 08:07:12 +00:00
|
|
|
void debug (FILE *debugfp) const noexcept
|
|
|
|
{
|
|
|
|
notcurses_debug (nc, debugfp);
|
|
|
|
}
|
|
|
|
|
2020-01-07 22:51:34 +00:00
|
|
|
Plane* get_stdplane () noexcept
|
|
|
|
{
|
|
|
|
return new Plane (notcurses_stdplane (nc), true);
|
|
|
|
}
|
|
|
|
|
2020-02-22 19:01:52 +00:00
|
|
|
Plane* get_stdplane (int *y, int *x)
|
|
|
|
{
|
|
|
|
if (y == nullptr)
|
|
|
|
throw invalid_argument ("'y' must be a valid pointer");
|
|
|
|
if (x == nullptr)
|
|
|
|
throw invalid_argument ("'x' must be a valid pointer");
|
|
|
|
|
|
|
|
return get_stdplane (*y, *x);
|
|
|
|
}
|
|
|
|
|
|
|
|
Plane* get_stdplane (int &y, int &x) noexcept
|
|
|
|
{
|
|
|
|
return new Plane (notcurses_stddim_yx (nc, &y, &x));
|
|
|
|
}
|
|
|
|
|
2020-01-07 22:51:34 +00:00
|
|
|
Plane* get_top () noexcept;
|
|
|
|
|
|
|
|
private:
|
|
|
|
notcurses *nc;
|
|
|
|
|
|
|
|
static NotCurses *_instance;
|
|
|
|
static std::mutex init_mutex;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|