mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-06 03:20:26 +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.
130 lines
2.8 KiB
C++
130 lines
2.8 KiB
C++
#ifndef __NCPP_DIRECT_HH
|
|
#define __NCPP_DIRECT_HH
|
|
|
|
#include <cstdio>
|
|
#include <notcurses/notcurses.h>
|
|
|
|
#include "Root.hh"
|
|
#include "Cell.hh"
|
|
|
|
namespace ncpp
|
|
{
|
|
class NotCurses;
|
|
|
|
class NCPP_API_EXPORT Direct : public Root
|
|
{
|
|
public:
|
|
explicit Direct (const char *termtype = nullptr, FILE *fp = nullptr, NotCurses *ncinst = nullptr)
|
|
: Root (ncinst)
|
|
{
|
|
direct = ncdirect_init (termtype, fp == nullptr ? stdout : fp);
|
|
if (direct == nullptr)
|
|
throw init_error ("Notcurses failed to initialize direct mode");
|
|
}
|
|
|
|
~Direct ()
|
|
{
|
|
ncdirect_stop (direct);
|
|
}
|
|
|
|
bool clear () const NOEXCEPT_MAYBE
|
|
{
|
|
return error_guard (ncdirect_clear (direct), -1);
|
|
}
|
|
|
|
bool set_fg_default () const NOEXCEPT_MAYBE
|
|
{
|
|
return error_guard (ncdirect_fg_default (direct), -1);
|
|
}
|
|
|
|
bool set_fg (unsigned rgb) const NOEXCEPT_MAYBE
|
|
{
|
|
return error_guard (ncdirect_fg (direct, rgb), -1);
|
|
}
|
|
|
|
bool set_fg (unsigned r, unsigned g, unsigned b) const NOEXCEPT_MAYBE
|
|
{
|
|
return error_guard (ncdirect_fg_rgb8 (direct, r, g, b), -1);
|
|
}
|
|
|
|
bool set_bg_default () const NOEXCEPT_MAYBE
|
|
{
|
|
return error_guard (ncdirect_bg_default (direct), -1);
|
|
}
|
|
|
|
bool set_bg (unsigned rgb) const NOEXCEPT_MAYBE
|
|
{
|
|
return error_guard (ncdirect_bg (direct, rgb), -1);
|
|
}
|
|
|
|
bool set_bg (unsigned r, unsigned g, unsigned b) const NOEXCEPT_MAYBE
|
|
{
|
|
return error_guard (ncdirect_bg_rgb8 (direct, r, g, b), -1);
|
|
}
|
|
|
|
int get_dim_x () const NOEXCEPT_MAYBE
|
|
{
|
|
return error_guard (ncdirect_dim_x (direct), -1);
|
|
}
|
|
|
|
int get_dim_y () const NOEXCEPT_MAYBE
|
|
{
|
|
return error_guard (ncdirect_dim_y (direct), -1);
|
|
}
|
|
|
|
void styles_set (CellStyle stylebits) const noexcept
|
|
{
|
|
ncdirect_styles_set (direct, static_cast<unsigned>(stylebits));
|
|
}
|
|
|
|
void styles_on (CellStyle stylebits) const noexcept
|
|
{
|
|
ncdirect_styles_on (direct, static_cast<unsigned>(stylebits));
|
|
}
|
|
|
|
void styles_off (CellStyle stylebits) const noexcept
|
|
{
|
|
ncdirect_styles_off (direct, static_cast<unsigned>(stylebits));
|
|
}
|
|
|
|
bool cursor_move_yx (int y, int x) const NOEXCEPT_MAYBE
|
|
{
|
|
return error_guard (ncdirect_cursor_move_yx (direct, y, x), -1);
|
|
}
|
|
|
|
bool cursor_up (int num) const NOEXCEPT_MAYBE
|
|
{
|
|
return error_guard (ncdirect_cursor_up (direct, num), -1);
|
|
}
|
|
|
|
bool cursor_left (int num) const NOEXCEPT_MAYBE
|
|
{
|
|
return error_guard (ncdirect_cursor_left (direct, num), -1);
|
|
}
|
|
|
|
bool cursor_right (int num) const NOEXCEPT_MAYBE
|
|
{
|
|
return error_guard (ncdirect_cursor_right (direct, num), -1);
|
|
}
|
|
|
|
bool cursor_down (int num) const NOEXCEPT_MAYBE
|
|
{
|
|
return error_guard (ncdirect_cursor_down (direct, num), -1);
|
|
}
|
|
|
|
bool cursor_enable () const NOEXCEPT_MAYBE
|
|
{
|
|
return error_guard (ncdirect_cursor_enable (direct), -1);
|
|
}
|
|
|
|
bool cursor_disable () const NOEXCEPT_MAYBE
|
|
{
|
|
return error_guard (ncdirect_cursor_disable (direct), -1);
|
|
}
|
|
|
|
private:
|
|
ncdirect *direct;
|
|
};
|
|
}
|
|
#endif
|