mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-23 07:59:03 -04:00
Fixes: https://github.com/dankamongmen/notcurses/issues/1025 Added: * Direct: flush (`ncdirect_flush`) * Direct: getc (`ncdirect_getc_blocking` and `ncdirect_getc_nblock`) * Direct: getc (`ncdirect_getc`) * Direct: get_inputready_fd (`ncdirect_inputready_fd`) * NotCurses: align (`notcurses_align`) * NotCurses: ucs32_to_utf8 (`notcurses_ucs32_to_utf8`) * NotCurses: get_bottom (`notcurses_bottom`) * Plane: resize_realign (`ncplane_resize_realign`) * Plane: get_x (`ncplane_x`) * Plane: get_y (`ncplane_y`) * Plane: mergedown (`ncplane_mergedown`) * Plane: putwc_stained (`ncplane_putwc_stained`) * Plane: putstr_stained (`ncplane_putstr_stained`) * Plane: set_fchannel (`ncplane_set_fchannel`) * Plane: set_bchannel (`ncplane_set_bchannel`) * Plane: get_styles (`ncplane_styles`) * Plane: get_above (`ncplane_above`) * Reader: move_left (`ncreader_move_left`) * Reader: move_right (`ncreader_move_right`) * Reader: move_up (`ncreader_move_up`) * Reader: move_down (`ncreader_move_down`) * Reader: write_egc (`ncreader_write_egc`) * Visual: get_default_blitter (`ncvisual_default_blitter`) Fixed: * NotCurses: `cursor_{enable,disable}` must use `NOEXCEPT_MAYBE` * Plane: renamed `putcw` to `putwc`
103 lines
2.2 KiB
C++
103 lines
2.2 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, const ncreader_options *opts)
|
|
: Reader (static_cast<const Plane*>(p), opts)
|
|
{}
|
|
|
|
explicit Reader (Plane const* p, 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), opts);
|
|
}
|
|
|
|
explicit Reader (Plane &p, const ncreader_options *opts)
|
|
: Reader (static_cast<Plane const&>(p), opts)
|
|
{}
|
|
|
|
explicit Reader (Plane const& p, const ncreader_options *opts)
|
|
: Root (Utilities::get_notcurses_cpp (p))
|
|
{
|
|
common_init (Utilities::to_ncplane (p), 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);
|
|
}
|
|
|
|
//
|
|
// None of the move* methods should throw since their return value (0 - moved, -1 - not moved) appear to be
|
|
// purely informational, not errors per se. If we had `can_move*` functions then `move*` could throw exceptions,
|
|
// potentially.
|
|
//
|
|
int move_left () const noexcept
|
|
{
|
|
return ncreader_move_left (reader);
|
|
}
|
|
|
|
int move_right () const noexcept
|
|
{
|
|
return ncreader_move_right (reader);
|
|
}
|
|
|
|
int move_up () const noexcept
|
|
{
|
|
return ncreader_move_up (reader);
|
|
}
|
|
|
|
int move_down () const noexcept
|
|
{
|
|
return ncreader_move_down (reader);
|
|
}
|
|
|
|
bool write_egc (const char *egc) const NOEXCEPT_MAYBE
|
|
{
|
|
return error_guard (ncreader_write_egc (reader, egc), -1);
|
|
}
|
|
|
|
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, const ncreader_options *opts)
|
|
{
|
|
reader = ncreader_create (n, opts);
|
|
if (reader == nullptr)
|
|
throw init_error ("Notcurses failed to create a new reader");
|
|
}
|
|
|
|
private:
|
|
ncreader *reader;
|
|
};
|
|
}
|
|
#endif
|