[input] introduce NCKEY_EOF #2185

This commit is contained in:
nick black 2021-09-19 22:16:31 -04:00
parent ea5da346f0
commit 3faf8ee3fb
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
6 changed files with 153 additions and 138 deletions

View File

@ -19,6 +19,7 @@ rearrangements of Notcurses.
`NCKEY_RELEASE` definition is no longer returned; instead, the
appropriate `NCKEY_BUTTONx` synthesized key is returned, with
`EVTYPE_RELEASE` set.
* `NCKEY_EOF` now indicates the end of input.
* 2.4.1 (2021-09-12)
* `notcurses_check_pixel_support()` still returns 0 if there is no support

View File

@ -668,7 +668,7 @@ must be readable without delay for it to be interpreted as such.
#define NCKEY_BUTTON2 suppuabize(202)
#define NCKEY_BUTTON3 suppuabize(203)
// ... up to 11 mouse buttons
#define NCKEY_RELEASE suppuabize(212)
#define NCKEY_EOF suppuabize(300)
// Is this uint32_t a Supplementary Private Use Area-B codepoint?
static inline bool
@ -760,7 +760,7 @@ int notcurses_mouse_disable(struct notcurses* n);
// Is the event a synthesized mouse event?
static inline bool
nckey_mouse_p(uint32_t r){
return r >= NCKEY_BUTTON1 && r <= NCKEY_RELEASE;
return r >= NCKEY_BUTTON1 && r <= NCKEY_BUTTON11;
}
```

View File

@ -126,6 +126,12 @@ next call to **notcurses_render**, when notcurses will pick up the resize
itself. If the **SIGWINCH** handler is inhibited, **NCKEY_RESIZE** is never
generated.
## **NCKEY_EOF**
Upon reaching the end of input, **NCKEY_EOF** will be returned. At this point,
any further calls will immediately return **NCKEY_EOF**. Note that this does
not necessarily result from pressing e.g. Ctrl+D.
# RETURN VALUES
On error, the **get** family of functions return **(uint32_t)-1**. The cause

View File

@ -113,6 +113,10 @@ extern "C" {
#define NCKEY_BUTTON10 suppuabize(210)
#define NCKEY_BUTTON11 suppuabize(211)
// indicates that we have reached the end of input. any further calls
// will continute to return this immediately.
#define NCKEY_EOF suppuabize(300)
// Synonyms (so far as we're concerned)
#define NCKEY_SCROLL_UP NCKEY_BUTTON4
#define NCKEY_SCROLL_DOWN NCKEY_BUTTON5

View File

@ -280,7 +280,7 @@ int input_demo(ncpp::NotCurses* nc) {
if(r == 0){ // interrupted by signal
continue;
}
if((r == 'D' || r == 'd') && ni.ctrl){
if(((r == 'D' || r == 'd') && ni.ctrl) || r == NCKEY_EOF){
done = true;
tid.join();
ncuplot_destroy(plot);

View File

@ -1997,7 +1997,11 @@ internal_get(inputctx* ictx, const struct timespec* ts, ncinput* ni){
if(ictx->stdineof){
pthread_mutex_unlock(&ictx->ilock);
logwarn("read eof on stdin\n");
return -1;
if(ni){
memset(ni, 0, sizeof(*ni));
ni->id = NCKEY_EOF;
}
return NCKEY_EOF;
}
if(ts == NULL){
pthread_cond_wait(&ictx->icond, &ictx->ilock);