mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 09:09:03 -04:00
add new notcurses-input binary #8
This commit is contained in:
parent
b3a0b2ed6b
commit
a037cdfe5a
@ -63,6 +63,22 @@ target_compile_options(notcurses-demo
|
||||
-Wall -Wextra -W -Wshadow
|
||||
)
|
||||
|
||||
file(GLOB INPUTSRCS CONFIGURE_DEPENDS src/input/*.cpp)
|
||||
add_executable(notcurses-input ${INPUTSRCS})
|
||||
target_include_directories(notcurses-input
|
||||
PRIVATE
|
||||
include
|
||||
"${PROJECT_BINARY_DIR}/include"
|
||||
)
|
||||
target_link_libraries(notcurses-input
|
||||
PRIVATE
|
||||
notcurses
|
||||
)
|
||||
target_compile_options(notcurses-input
|
||||
PRIVATE
|
||||
-Wall -Wextra -W -Wshadow
|
||||
)
|
||||
|
||||
file(GLOB VIEWSRCS CONFIGURE_DEPENDS src/view/*.cpp)
|
||||
add_executable(notcurses-view ${VIEWSRCS})
|
||||
target_include_directories(notcurses-view
|
||||
@ -135,6 +151,7 @@ install(FILES
|
||||
|
||||
install(TARGETS notcurses-demo DESTINATION bin)
|
||||
install(TARGETS notcurses-view DESTINATION bin)
|
||||
install(TARGETS notcurses-input DESTINATION bin)
|
||||
install(TARGETS notcurses
|
||||
LIBRARY
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
|
@ -174,10 +174,9 @@ API int ncplane_move_below(struct ncplane* RESTRICT n, struct ncplane* RESTRICT
|
||||
// Splice ncplane 'n' out of the z-buffer, and reinsert it above 'above'.
|
||||
API int ncplane_move_above(struct ncplane* RESTRICT n, struct ncplane* RESTRICT above);
|
||||
|
||||
// Retrieve the topmost cell at this location on the screen, returning it in
|
||||
// 'c'. If there is more than a byte of gcluster, it will be returned as a heap
|
||||
// allocation in '*gclust', and '*c' will be 0x80.
|
||||
API void notcurses_getc(const struct notcurses* n, cell* c, char** gclust);
|
||||
// Retrieve the topmost cell at the cursor location on the specified plane,
|
||||
// returning it in 'c'. This copy is safe to use until the ncplane is destroyed.
|
||||
API void ncplane_at_cursor(const struct ncplane* n, cell* c);
|
||||
|
||||
// Manipulate the opaque user pointer associated with this plane.
|
||||
// ncplane_set_userptr() returns the previous userptr after replacing
|
||||
@ -212,10 +211,18 @@ API void ncplane_cursor_yx(const struct ncplane* n, int* RESTRICT y,
|
||||
// On failure, -1 is returned.
|
||||
API int ncplane_putc(struct ncplane* n, const cell* c);
|
||||
|
||||
// Retrieve the cell under this plane's cursor, returning it in 'c'. If there
|
||||
// is more than a byte of gcluster, it will be returned as a heap allocation in
|
||||
// '*gclust', and '*c' will be 0x80. Returns -1 on error, 0 on success.
|
||||
API int ncplane_getc(const struct ncplane* n, cell* c, char** gclust);
|
||||
// Return an input from stdin, if one is available. Note that we do *not*
|
||||
// attempt to read an EGC in its entirety. 'c' will reference a single
|
||||
// UTF-8-encoded Unicode codepoint. This is a non-blocking operation. If no
|
||||
// input is available, 0 is returned. On other errors, -1 is returned.
|
||||
// Otherwise, the number of bytes in the UTF-8 character are returned.
|
||||
API int ncplane_getc(const struct ncplane* n, cell* c);
|
||||
|
||||
// The same as ncplane_getc(), but blocking until input is read. It can still
|
||||
// return early due to interruption by signal, in which case 0 is returned. On
|
||||
// any other error, -1 is returned. Otherwise, the number of bytes in the UTF-8
|
||||
// character are returned.
|
||||
API int ncplane_getc_blocking(const struct ncplane* n, cell* c);
|
||||
|
||||
// Write a series of cells to the current location, using the current style.
|
||||
// They will be interpreted as a series of columns (according to the definition
|
||||
|
16
src/input/input.cpp
Normal file
16
src/input/input.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
#include <cstdlib>
|
||||
#include <notcurses.h>
|
||||
|
||||
int main(void){
|
||||
notcurses_options opts{};
|
||||
opts.outfp = stdout;
|
||||
struct notcurses* nc = notcurses_init(&opts);
|
||||
if(nc == NULL){
|
||||
return EXIT_FAILURE;;
|
||||
}
|
||||
// FIXME read input
|
||||
if(notcurses_stop(nc)){
|
||||
return EXIT_FAILURE;;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
@ -1062,7 +1062,7 @@ int ncplane_putc(ncplane* n, const cell* c){
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ncplane_getc(const ncplane* n, cell* c, char** gclust){
|
||||
int ncplane_cursor_at(const ncplane* n, cell* c, char** gclust){
|
||||
if(n->y == n->leny && n->x == n->lenx){
|
||||
return -1;
|
||||
}
|
||||
@ -1291,3 +1291,13 @@ void ncplane_erase(ncplane* n){
|
||||
n->channels = 0;
|
||||
n->attrword = 0;
|
||||
}
|
||||
|
||||
int ncplane_getc(const struct ncplane* n, cell* c){
|
||||
int r = getc(n->nc->ttyfp);
|
||||
return r;
|
||||
}
|
||||
|
||||
int ncplane_getc_blocking(const struct ncplane* n, cell* c){
|
||||
int r = getc(n->nc->ttyfp);
|
||||
return r;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user