Skip to content

Commit

Permalink
[Misc] A hodgepodge of tiny changes
Browse files Browse the repository at this point in the history
CMake:
  Simplify cmake target+version config generation and make it actually
  work.  With the changes it is now possible to detect and use
  `Notcurses` in the following way:

     find_package(Notcurses REQUIRED)
     ...
     target_link_libraries(myapp PRIVATE notcurses::notcurses)

  Also, added the same CMake configuration for `Notcurses++`, to be used
  in the following way:

     find_package(Notcurses REQUIRED
     find_package(Notcurses++ REQUIRED)
     ...
     target_link_libraries(myapp PRIVATE notcurses++::notcurses++)

Docs:
  `notcurses_cell(3)`: `cell_styles_{on,off} -> cell_{on,off}_styles`
  and `cell_load_simple` -> `cell_load_char`

C++ API:
  * Plane: added constructors taking `ncplane_options const&` instead of
    the multitude of individual parameters
  * Plane: drop `struct` when `ncplane_options` is used.
  * Plane: added `strdup` (`cell_strdup`)
  * Plane: added `extract` (`cell_extract`)
  • Loading branch information
grendello authored and dankamongmen committed Nov 28, 2020
1 parent 059007b commit c5c9432
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 34 deletions.
36 changes: 30 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -601,23 +601,47 @@ include(CMakePackageConfigHelpers)
configure_file(tools/version.h.in include/version.h)
configure_file(tools/builddef.h.in include/builddef.h)

configure_package_config_file(tools/NotcursesConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/NotcursesConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/notcurses/cmake
)

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/NotcursesConfigVersion.cmake
COMPATIBILITY SameMajorVersion
)

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/Notcurses++ConfigVersion.cmake
COMPATIBILITY SameMajorVersion
)

# Installation
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/NotcursesConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/NotcursesConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Notcurses"
)

install(TARGETS notcurses
EXPORT "NotcursesTargets"
)

install(EXPORT "NotcursesTargets"
NAMESPACE "notcurses::"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Notcurses"
FILE "NotcursesConfig.cmake"
)

install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/Notcurses++ConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Notcurses++"
)

install(TARGETS notcurses++
EXPORT "Notcurses++Targets"
)

install(EXPORT "Notcurses++Targets"
NAMESPACE "notcurses++::"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Notcurses++"
FILE "Notcurses++Config.cmake"
)

install(FILES
${CMAKE_CURRENT_BINARY_DIR}/notcurses.pc
DESTINATION ${PKGCONFIG_DIR}
Expand Down
6 changes: 3 additions & 3 deletions doc/man/man3/notcurses_cell.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ typedef struct cell {
**unsigned cell_styles(const cell* ***c***);**
**void cell_styles_on(cell* ***c***, unsigned ***stylebits***);**
**void cell_on_styles(cell* ***c***, unsigned ***stylebits***);**
**void cell_styles_off(cell* ***c***, unsigned ***stylebits***);**
**void cell_off_styles(cell* ***c***, unsigned ***stylebits***);**
**void cell_set_fg_default(cell* ***c***);**
Expand All @@ -74,7 +74,7 @@ typedef struct cell {
**char* cell_strdup(const struct ncplane* ***n***, const cell* ***c***);**
**int cell_load_simple(struct ncplane* ***n***, cell* ***c***, char ***ch***);**
**int cell_load_char(struct ncplane* ***n***, cell* ***c***, char ***ch***);**
**char* cell_extract(const struct ncplane* ***n***, const cell* ***c***, uint16_t* ***stylemask***, uint64_t* ***channels***);**
Expand Down
61 changes: 45 additions & 16 deletions include/ncpp/Plane.hh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ namespace ncpp
plane = create_plane (*n, rows, cols, yoff, xoff, opaque);
}

explicit Plane (Plane *n, ncplane_options const& nopts, NotCurses *ncinst = nullptr)
: Plane (static_cast<const Plane*>(n), nopts, ncinst)
{}

explicit Plane (const Plane *n, ncplane_options const& nopts, NotCurses *ncinst = nullptr)
: Root (ncinst)
{
if (n == nullptr) {
throw invalid_argument ("'n' must be a valid pointer");
}

plane = create_plane (*n, nopts);
}

explicit Plane (const Plane &n, int rows, int cols, int yoff, int xoff, void *opaque = nullptr)
: Root (nullptr)
{
Expand All @@ -69,7 +83,7 @@ namespace ncpp
explicit Plane (int rows, int cols, int yoff, int xoff, void *opaque = nullptr, NotCurses *ncinst = nullptr)
: Root (ncinst)
{
struct ncplane_options nopts = {
ncplane_options nopts = {
.y = yoff,
.x = xoff,
.rows = rows,
Expand Down Expand Up @@ -102,6 +116,16 @@ namespace ncpp
plane = create_plane (const_cast<Plane&>(n), rows, cols, yoff, align, opaque);
}

explicit Plane (Plane &n, ncplane_options const& nopts, NotCurses *ncinst = nullptr)
: Plane (static_cast<Plane const&>(n), nopts, ncinst)
{}

explicit Plane (Plane const& n, ncplane_options const& nopts, NotCurses *ncinst = nullptr)
: Root (ncinst)
{
plane = create_plane (n, nopts);
}

explicit Plane (Plane *n, int rows, int cols, int yoff, NCAlign align, void *opaque = nullptr)
: Root (nullptr)
{
Expand Down Expand Up @@ -1130,6 +1154,16 @@ namespace ncpp
return error_guard (ncplane_rotate_ccw (plane), -1);
}

char* strdup (Cell const& cell) const noexcept
{
return cell_strdup (plane, cell);
}

char* extract (Cell const& cell, uint16_t *stylemask = nullptr, uint64_t *channels = nullptr)
{
return cell_extract (plane, cell, stylemask, channels);
}

const char* get_extended_gcluster (Cell &cell) const noexcept
{
return cell_extended_gcluster (plane, cell);
Expand Down Expand Up @@ -1227,27 +1261,17 @@ namespace ncpp
private:
ncplane* create_plane (const Plane &n, int rows, int cols, int yoff, int xoff, void *opaque)
{
struct ncplane_options nopts = {
ncplane_options nopts = {
.y = yoff,
.x = xoff,
.x = xoff,
.rows = rows,
.cols = cols,
.userptr = opaque,
.name = nullptr,
.resizecb = nullptr,
.flags = 0,
};
ncplane *ret = ncplane_create (
n.plane,
&nopts
);

if (ret == nullptr)
throw init_error ("Notcurses failed to create a new plane");

map_plane (plane, this);

return ret;
return create_plane (n, nopts);
}

ncplane* create_plane (Plane &n, int rows, int cols, int yoff, NCAlign align, void *opaque)
Expand All @@ -1262,16 +1286,21 @@ namespace ncpp
nullptr,
0,
};
return create_plane (n, nopts);
}

ncplane* create_plane (const Plane &n, ncplane_options const& nopts)
{
ncplane *ret = ncplane_create (
n.plane,
&nopts
);

if (ret == nullptr)
if (ret == nullptr) {
throw init_error ("Notcurses failed to create an aligned plane");
}

map_plane (plane, this);

return ret;
}

Expand Down
9 changes: 0 additions & 9 deletions tools/NotcursesConfig.cmake.in

This file was deleted.

0 comments on commit c5c9432

Please sign in to comment.