zoo demo: show cursor in reader box #835

pull/957/head
nick black 4 years ago committed by Nick Black
parent 3495269bcb
commit 7cbb2e9110

@ -6,9 +6,6 @@ rearrangements of Notcurses.
functions which once returned `nc_err_e` now return a bimodal `int`. Those
functions which accepted a value-result `nc_err_e*` no longer take this
argument.
* `notcurses_cursor_move_yx()` has been added for placement of the terminal
cursor. Remember, you must call `notcurses_cursor_enable()` before it will
be made visible.
* `notcurses_cursor_enable()` now takes two `int` parameters specifying the
desired location of the cursor. Both `notcurses_cursor_enable()` and
`notcurses_cursor_disable()` now return `int` rather than `void`.

@ -228,15 +228,10 @@ notcurses_term_dim_yx(const struct notcurses* n, int* restrict rows,
int notcurses_refresh(struct notcurses* n, int* restrict y, int* restrict x);
// Enable or disable the terminal's cursor, if supported. Immediate effect.
// It is an error to supply coordinates outside of the standard plane.
void notcurses_cursor_enable(struct notcurses* nc, int y, int x);
void notcurses_cursor_disable(struct notcurses* nc);
// Move the terminal cursor to the specified location. If 'y' or 'x' is
// negative, there is no movement along that axis. Returns error if the
// coordinates are outside the viewing area. The cursor must be explicitly
// enabled with notcurses_cursor_enable() to be seen.
int notcurses_cursor_move_yx(struct notcurses* nc, int y, int x);
// Returns a 16-bit bitmask in the LSBs of supported curses-style attributes
// (NCSTYLE_UNDERLINE, NCSTYLE_BOLD, etc.) The attribute is only
// indicated as supported if the terminal can support it together with color.

@ -48,8 +48,6 @@ typedef struct notcurses_options {
**int notcurses_cursor_enable(struct notcurses* nc, int y, int x);**
**int notcurses_cursor_move_yx(struct notcurses* nc, int y, int x);**
**int notcurses_cursor_disable(struct notcurses* nc);**
# DESCRIPTION
@ -79,9 +77,9 @@ by setting **NCOPTION_NO_ALTERNATE_SCREEN** in **flags**. Users tend to have
strong opinions regarding the alternate screen, so it's often useful to expose
this via a command-line option.
notcurses hides the cursor by default. It can be dynamically enabled or
notcurses hides the cursor by default. It can be dynamically enabled, moved, or
disabled during execution via **notcurses_cursor_enable(3)** and
**notcurses_cursor_disable(3)**, and moved with **notcurses_cursor_move_yx()**.
**notcurses_cursor_disable(3)**.
**notcurses_init** typically emits some diagnostics at startup, including version
information and some details of the configured terminal. This can be inhibited

@ -161,11 +161,6 @@ namespace ncpp
return error_guard (notcurses_cursor_disable (nc), -1);
}
int cursor_move_yx (int y, int x) const noexcept
{
return error_guard (notcurses_cursor_move_yx (nc, y, x), -1);
}
void get_stats (ncstats *stats) const noexcept
{
if (stats == nullptr)

@ -2574,12 +2574,6 @@ bprefix(uintmax_t val, uintmax_t decimal, char* buf, int omitdec){
API int notcurses_cursor_enable(struct notcurses* nc, int y, int x);
API int notcurses_cursor_disable(struct notcurses* nc);
// Move the terminal cursor to the specified location. If 'y' or 'x' is
// negative, there is no movement along that axis. Returns error if the
// coordinates are outside the viewing area. The cursor must be explicitly
// enabled with notcurses_cursor_enable() to be seen.
API int notcurses_cursor_move_yx(struct notcurses* nc, int y, int x);
// Palette API. Some terminals only support 256 colors, but allow the full
// palette to be specified with arbitrary RGB colors. In all cases, it's more
// performant to use indexed colors, since it's much less data to write to the

@ -432,7 +432,6 @@ int ncdirect_render_image(struct ncdirect* n, const char* filename, ncalign_e al
struct ncplane* ncplane_parent(struct ncplane* n);
const struct ncplane* ncplane_parent_const(const struct ncplane* n);
int notcurses_cursor_enable(struct notcurses* nc, int y, int x);
int notcurses_cursor_move_yx(struct notcurses* nc, int y, int x);
int notcurses_cursor_disable(struct notcurses* nc);
int ncreader_move_left(struct ncreader* n);
int ncreader_move_right(struct ncreader* n);

@ -158,6 +158,11 @@ layout_next_text(struct ncreader* reader, const char* text, size_t* textpos){
free(duped);
return -1;
}
int y, x, posy, posx;
struct ncplane* ncp = ncreader_plane(reader);
ncplane_cursor_yx(ncp, &y, &x);
ncplane_yx(ncp, &posy, &posx);
notcurses_cursor_enable(ncplane_notcurses(ncp), y + posy, x + posx);
free(duped);
*textpos += towrite;
}
@ -182,8 +187,9 @@ static int
selector_run(struct notcurses* nc, struct ncreader* reader, struct ncselector* selector){
const char text[] =
"Notcurses provides several widgets to quickly build vivid TUIs.\n\n"
"This NCReader widget facilitates free-form text entry complete with readline-style bindings. "
"NCSelector allows a single option to be selected from a list. ";
"This NCReader widget facilitates free-form text entry complete with readline-style bindings.\n\n"
"NCSelector allows a single option to be selected from a list.\n\n"
"NCFdplane streams a file descriptor, while NCSubproc spawns a subprocess and streams its output. ";
int ret = 0, dimy, dimx;
ncplane_dim_yx(notcurses_stdplane(nc), &dimy, &dimx);
const int centery = (dimy - ncplane_dim_y(ncreader_plane(reader))) / 2;
@ -198,7 +204,7 @@ selector_run(struct notcurses* nc, struct ncreader* reader, struct ncselector* s
int xi = 1;
int yi = 1;
struct timespec iterdelay, start;
timespec_div(&demodelay, iters, &iterdelay);
timespec_div(&demodelay, iters / 4, &iterdelay);
size_t textpos = 0;
clock_gettime(CLOCK_MONOTONIC, &start);
for(int i = 0 ; i < iters ; ++i){
@ -244,8 +250,7 @@ selector_run(struct notcurses* nc, struct ncreader* reader, struct ncselector* s
static int
mselector_run(struct notcurses* nc, struct ncreader* reader, struct ncmultiselector* mselector){
const char text[] =
"NCMultiselector allows 0..n options to be selected from a list of n items. "
"NCFdplane streams a file descriptor, while NCSubproc spawns a subprocess and streams its output. "
"NCMultiselector allows 0..n options to be selected from a list of n items.\n\n"
"A variety of plots are supported, and menus can be placed along the top and/or bottom of any plane.\n\n"
"Widgets can be controlled with the keyboard and/or mouse. They are implemented atop ncplanes, and these planes can be manipulated like all others.";
int ret = 0, dimy, dimx;
@ -262,7 +267,7 @@ mselector_run(struct notcurses* nc, struct ncreader* reader, struct ncmultiselec
int xi = 1;
int yi = 1;
struct timespec iterdelay, start;
timespec_div(&demodelay, iters, &iterdelay);
timespec_div(&demodelay, iters / 4, &iterdelay);
clock_gettime(CLOCK_MONOTONIC, &start);
size_t textpos = 0;
for(int i = 0 ; i < iters ; ++i){
@ -356,6 +361,9 @@ done:
ncselector_destroy(selector, NULL);
ncmultiselector_destroy(mselector);
ncreader_destroy(reader, NULL);
if(notcurses_cursor_disable(nc)){
return -1;
}
return ret;
}

@ -55,7 +55,7 @@ static int
ncreader_redraw(ncreader* n){
int ret = 0;
//fprintf(stderr, "redraw: xproj %d\n", n->xproject);
notcurses_debug(n->ncp->nc, stderr);
//notcurses_debug(n->ncp->nc, stderr);
assert(n->xproject >= 0);
assert(n->textarea->lenx >= n->ncp->lenx);
assert(n->textarea->leny >= n->ncp->leny);

@ -1101,10 +1101,6 @@ int ncdirect_fg(ncdirect* nc, unsigned rgb){
}
int notcurses_cursor_enable(notcurses* nc, int y, int x){
if(nc->cursory >= 0 || nc->cursorx >= 0){
logerror(nc, "Cursor is already enabled\n");
return -1;
}
if(y < 0 || x < 0){
logerror(nc, "Illegal cursor placement: %d, %d\n", y, x);
return -1;
@ -1115,11 +1111,18 @@ int notcurses_cursor_enable(notcurses* nc, int y, int x){
}
if(nc->ttyfd >= 0){
if(nc->tcache.cnorm){
if(stage_cursor(nc, nc->ttyfp, y, x) == 0){
if(!tty_emit("cnorm", nc->tcache.cnorm, nc->ttyfd) && !fflush(nc->ttyfp)){
nc->cursory = y;
nc->cursorx = x;
return 0;
if(nc->cursory != y || nc->cursorx != x){
if(stage_cursor(nc, nc->ttyfp, y, x) == 0){
if(nc->cursory >= 0 && nc->cursorx >= 0){
nc->cursory = y;
nc->cursorx = x;
return 0;
}
if(!tty_emit("cnorm", nc->tcache.cnorm, nc->ttyfd) && !fflush(nc->ttyfp)){
nc->cursory = y;
nc->cursorx = x;
return 0;
}
}
}
}
@ -1143,20 +1146,3 @@ int notcurses_cursor_disable(notcurses* nc){
}
return -1;
}
int notcurses_cursor_move_yx(notcurses* nc, int y, int x){
if(nc->cursory < 0 || nc->cursorx < 0){
logerror(nc, "Cursor is not enabled");
return -1;
}
if(y < 0 || x < 0){
logerror(nc, "Illegal cursor placement: %d, %d\n", y, x);
return -1;
}
if(stage_cursor(nc, nc->ttyfp, y, x) || fflush(nc->ttyfp)){
return -1;
}
nc->cursory = y;
nc->cursorx = x;
return 0;
}

@ -39,7 +39,7 @@ auto main() -> int {
}
int y, x;
ncplane_cursor_yx(ncreader_plane(nr), &y, &x);
nc.cursor_move_yx(y + 2, x + 2);
nc.cursor_enable(y + 2, x + 2);
nc.render();
}
nc.render();

Loading…
Cancel
Save