2020-01-02 02:23:11 +00:00
|
|
|
% notcurses_input(3)
|
|
|
|
% nick black <nickblack@linux.com>
|
2021-11-19 02:36:24 +00:00
|
|
|
% v2.4.97
|
2020-01-02 02:23:11 +00:00
|
|
|
|
|
|
|
# NAME
|
|
|
|
|
2020-01-04 07:37:55 +00:00
|
|
|
notcurses_input - input via notcurses
|
2020-01-02 02:23:11 +00:00
|
|
|
|
|
|
|
# SYNOPSIS
|
|
|
|
|
2020-04-19 22:46:32 +00:00
|
|
|
**#include <notcurses/notcurses.h>**
|
2020-01-02 02:23:11 +00:00
|
|
|
|
|
|
|
```c
|
2020-02-12 03:44:45 +00:00
|
|
|
struct timespec;
|
|
|
|
struct notcurses;
|
|
|
|
|
2020-01-02 02:23:11 +00:00
|
|
|
typedef struct ncinput {
|
2021-07-25 04:38:33 +00:00
|
|
|
uint32_t id; // Unicode codepoint
|
2020-01-02 02:23:11 +00:00
|
|
|
int y; // Y cell coordinate of event, -1 for undefined
|
|
|
|
int x; // X cell coordinate of event, -1 for undefined
|
|
|
|
bool alt; // Was Alt held during the event?
|
|
|
|
bool shift; // Was Shift held during the event?
|
|
|
|
bool ctrl; // Was Ctrl held during the event?
|
2021-09-20 00:13:02 +00:00
|
|
|
enum {
|
|
|
|
EVTYPE_UNKNOWN,
|
|
|
|
EVTYPE_PRESS,
|
|
|
|
EVTYPE_REPEAT,
|
|
|
|
EVTYPE_RELEASE,
|
|
|
|
} evtype;
|
2021-11-05 12:32:35 +00:00
|
|
|
int ypx, xpx; // pixel offsets within cell, -1 for undefined
|
2020-01-02 02:23:11 +00:00
|
|
|
} ncinput;
|
2021-11-05 12:32:35 +00:00
|
|
|
|
|
|
|
#define NCMICE_NO_EVENTS 0
|
|
|
|
#define NCMICE_MOVE_EVENT 0x1
|
|
|
|
#define NCMICE_BUTTON_EVENT 0x2
|
|
|
|
#define NCMICE_DRAG_EVENT 0x4
|
|
|
|
#define NCMICE_ALL_EVENTS 0x7
|
2020-01-02 02:23:11 +00:00
|
|
|
```
|
|
|
|
|
2021-07-25 04:38:33 +00:00
|
|
|
**bool nckey_mouse_p(uint32_t ***r***);**
|
2020-01-02 02:23:11 +00:00
|
|
|
|
2021-05-22 00:06:36 +00:00
|
|
|
**bool ncinput_nomod_p(const ncinput* ***ni***);**
|
|
|
|
|
2021-07-25 04:38:33 +00:00
|
|
|
**uint32_t notcurses_get(struct notcurses* ***n***, const struct timespec* ***ts***, ncinput* ***ni***);**
|
2020-01-02 02:23:11 +00:00
|
|
|
|
2021-09-12 07:25:37 +00:00
|
|
|
**int notcurses_getvec(struct notcurses* ***n***, const struct timespec* ***ts***, ncinput* ***ni***, int vcount);**
|
|
|
|
|
2021-11-09 09:16:23 +00:00
|
|
|
**uint32_t notcurses_get_nblock(struct notcurses* ***n***, ncinput* ***ni***);**
|
2020-01-02 02:23:11 +00:00
|
|
|
|
2021-11-09 09:16:23 +00:00
|
|
|
**uint32_t notcurses_get_blocking(struct notcurses* ***n***, ncinput* ***ni***);**
|
2020-01-02 02:23:11 +00:00
|
|
|
|
2021-11-09 09:16:23 +00:00
|
|
|
**int cnotcurses_mice_enable(struct notcurses* ***n***, unsigned ***eventmask***);**
|
2020-01-02 02:23:11 +00:00
|
|
|
|
2021-11-05 12:32:35 +00:00
|
|
|
**int notcurses_mice_disable(struct notcurses* ***n***);**
|
2020-01-02 02:23:11 +00:00
|
|
|
|
2020-11-06 21:49:35 +00:00
|
|
|
**int notcurses_inputready_fd(struct notcurses* ***n***);**
|
2020-05-02 16:56:39 +00:00
|
|
|
|
2021-02-12 05:19:17 +00:00
|
|
|
**static inline bool ncinput_equal_p(const ncinput* ***n1***, const ncinput* ***n2***);**
|
2020-10-15 07:14:19 +00:00
|
|
|
|
2020-12-21 01:16:08 +00:00
|
|
|
**int notcurses_linesigs_disable(struct notcurses* ***n***);**
|
|
|
|
|
|
|
|
**int notcurses_linesigs_enable(struct notcurses* ***n***);**
|
|
|
|
|
2020-01-02 02:23:11 +00:00
|
|
|
# DESCRIPTION
|
|
|
|
|
2020-01-02 03:39:16 +00:00
|
|
|
notcurses supports input from keyboards and mice, and any device that looks
|
|
|
|
like them. Mouse support requires a broker such as GPM, Wayland, or Xorg, and
|
2021-11-09 09:16:23 +00:00
|
|
|
must be explicitly enabled via **notcurses_mice_enable**. The full 32-bit
|
2020-01-02 03:39:16 +00:00
|
|
|
range of Unicode is supported (see **unicode(7)**), with synthesized events
|
2021-11-09 09:16:23 +00:00
|
|
|
mapped above the 1,114,112 codepoints of Unicode 14.0's seventeen Planes.
|
2020-01-02 03:39:16 +00:00
|
|
|
Unicode characters are returned directly as UCS-32, one codepoint at a time.
|
|
|
|
|
|
|
|
notcurses takes its keyboard input from **stdin**, which will be placed into
|
2020-12-28 14:44:44 +00:00
|
|
|
non-blocking mode for the duration of operation. The terminal is put into
|
|
|
|
non-canonical mode (see **termios(3)**), and thus keys are received without line-buffering.
|
2020-01-02 03:39:16 +00:00
|
|
|
notcurses maintains its own buffer of input characters, which it will attempt
|
|
|
|
to fill whenever it reads.
|
|
|
|
|
2021-07-25 04:38:33 +00:00
|
|
|
**notcurses_get** allows a **struct timespec** to be specified as a timeout.
|
2021-11-09 09:16:23 +00:00
|
|
|
If ***ts*** is **NULL**, **notcurses_get** will block until it reads input, or
|
2021-10-26 13:59:33 +00:00
|
|
|
is interrupted by a signal. If its values are zeroes, there will be no
|
2021-11-09 09:16:23 +00:00
|
|
|
blocking. Otherwise, ***ts*** specifies an absolute deadline (taken against
|
2021-10-26 13:59:33 +00:00
|
|
|
**CLOCK_MONOTONIC**; see **clock_gettime(2)**). On timeout, 0 is returned.
|
2021-11-09 09:16:23 +00:00
|
|
|
Event details will be reported in ***ni***, unless ***ni*** is NULL.
|
2020-01-02 03:39:16 +00:00
|
|
|
|
2020-05-02 16:56:39 +00:00
|
|
|
**notcurses_inputready_fd** provides a file descriptor suitable for use with
|
|
|
|
I/O multiplexors such as **poll(2)**. This file descriptor might or might not
|
2021-07-25 04:38:33 +00:00
|
|
|
be the actual input file descriptor. If it readable, **notcurses_get** can
|
2020-05-02 16:56:39 +00:00
|
|
|
be called without the possibility of blocking.
|
|
|
|
|
2020-10-15 07:14:19 +00:00
|
|
|
**ncinput_equal_p** compares two **ncinput** structs for data equality (i.e.
|
2021-09-20 00:13:02 +00:00
|
|
|
not considering padding), returning **true** if they represent the same
|
|
|
|
input (though not necessarily the same input event).
|
2020-10-15 07:14:19 +00:00
|
|
|
|
2020-12-21 01:16:08 +00:00
|
|
|
**notcurses_linesigs_disable** disables conversion of inputs **INTR**, **QUIT**,
|
|
|
|
**SUSP**, and **DSUSP** into **SIGINT**, **SIGQUIT**, and **SIGTSTP**. These
|
|
|
|
conversions are enabled by default. **notcurses_linesigs_enable** undoes this
|
|
|
|
action, but signals in the interim are permanently lost.
|
|
|
|
|
2020-01-02 03:39:16 +00:00
|
|
|
## Mice
|
|
|
|
|
2021-11-05 12:32:35 +00:00
|
|
|
For mouse events, the additional fields ***y***, ***x***, ***ypx***, and
|
|
|
|
***xpx*** are set. These fields are not meaningful for keypress events.
|
|
|
|
Mouse events can be distinguished using the **nckey_mouse_p** predicate.
|
|
|
|
**NCMICE_MOVE_EVENT** requests events whenever the mouse moves when no
|
|
|
|
buttons are held down. **NCMICE_DRAG_EVENT** requests events when the mouse
|
|
|
|
is moving with buttons held down. **NCMICE_BUTTON_EVENT** requests events
|
|
|
|
then the button state changes. **NCMICE_ALL_EVENTS** is provided for
|
|
|
|
convenience and future-proofing against API (though not ABI) changes.
|
2020-01-02 03:39:16 +00:00
|
|
|
|
|
|
|
## Synthesized keypresses
|
|
|
|
|
|
|
|
Many keys do not have a Unicode representation, let alone ASCII. Examples
|
|
|
|
include the modifier keys (Alt, Meta, etc.), the "function" keys, and the arrow
|
|
|
|
keys on the numeric keypad. The special keys available to the terminal are
|
|
|
|
defined in the **terminfo(5)** entry, which notcurses loads on startup. Upon
|
|
|
|
receiving an escape code matching a terminfo input capability, notcurses
|
|
|
|
synthesizes a special value. An escape sequence must arrive in its entirety to
|
|
|
|
notcurses; running out of input in the middle of an escape sequence will see it
|
|
|
|
rejected. Likewise, any error while handling an escape sequence will see the
|
|
|
|
lex aborted, and the sequence thus far played back as independent literal
|
|
|
|
keystrokes.
|
|
|
|
|
|
|
|
The full list of synthesized keys (there are well over one hundred) can be
|
2020-04-19 22:46:32 +00:00
|
|
|
found in **<notcurses/notcurses.h>**. For more details, consult **terminfo(5)**.
|
2020-01-02 03:39:16 +00:00
|
|
|
|
|
|
|
## **NCKEY_RESIZE**
|
|
|
|
|
2020-05-02 16:56:39 +00:00
|
|
|
Unless the **SIGWINCH** handler has been inhibited (see **notcurses_init**),
|
2021-11-17 08:07:47 +00:00
|
|
|
Notcurses will automatically catch screen resizes, and synthesize an
|
2020-01-02 03:39:16 +00:00
|
|
|
**NCKEY_RESIZE** event. Upon receiving this event, the user may call
|
2020-05-02 16:56:39 +00:00
|
|
|
**notcurses_refresh** to force an immediate reflow, or just wait until the
|
|
|
|
next call to **notcurses_render**, when notcurses will pick up the resize
|
2020-01-02 03:39:16 +00:00
|
|
|
itself. If the **SIGWINCH** handler is inhibited, **NCKEY_RESIZE** is never
|
|
|
|
generated.
|
2020-01-02 02:23:11 +00:00
|
|
|
|
2021-11-17 08:07:47 +00:00
|
|
|
## **NCKEY_SIGNAL**
|
|
|
|
|
|
|
|
Unless the **SIGWINCH** handler has been inhibited (see **notcurses_init**),
|
|
|
|
Notcurses will catch **SIGCONT**, and synthesize an **NCKEY_SIGNAL** event.
|
|
|
|
This typically indicates that the program has been restarted after being
|
|
|
|
paused or placed in the background. The next rasterization will be a full
|
|
|
|
rebuild of the screen, as if **notcurses_refresh** had been called; the user
|
|
|
|
might wish to immediately call **notcurses_refresh** themselves.
|
|
|
|
|
2021-09-20 02:16:31 +00:00
|
|
|
## **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.
|
|
|
|
|
2020-01-02 02:23:11 +00:00
|
|
|
# RETURN VALUES
|
|
|
|
|
2021-07-25 04:38:33 +00:00
|
|
|
On error, the **get** family of functions return **(uint32_t)-1**. The cause
|
|
|
|
of the error may be determined using **errno(3)**. Unless the error was a
|
|
|
|
temporary one (especially e.g. **EINTR**), **notcurses_get** probably cannot
|
|
|
|
be usefully called forthwith. On a timeout, 0 is returned. Otherwise, the
|
|
|
|
UCS-32 value of a Unicode codepoint, or a synthesized event, is returned.
|
2020-01-02 03:39:16 +00:00
|
|
|
|
2021-09-12 07:25:37 +00:00
|
|
|
If an error is encountered before **notcurses_getvec** has read any input,
|
|
|
|
it will return -1. If it times out before reading any input, it will return
|
|
|
|
0. Otherwise, it returns the number of **ncinput** objects written back.
|
|
|
|
|
2021-11-05 12:32:35 +00:00
|
|
|
**notcurses_mice_enable** returns 0 on success, and non-zero on failure, as
|
|
|
|
does **notcurses_mice_disable**. Success does not necessarily mean that a
|
|
|
|
mouse is available nor that all requested events will be generated.
|
2020-01-02 03:39:16 +00:00
|
|
|
|
2020-11-05 21:31:07 +00:00
|
|
|
**ncinput_equal_p** returns **true** if the two **ncinput** structs represent
|
|
|
|
the same input (though not necessarily the same input event), and
|
|
|
|
**false** otherwise.
|
2020-10-15 07:14:19 +00:00
|
|
|
|
2020-01-02 03:39:16 +00:00
|
|
|
# NOTES
|
|
|
|
|
2021-07-25 04:38:33 +00:00
|
|
|
Like any other notcurses function, it is an error to call **notcurses_get**
|
2020-05-02 16:56:39 +00:00
|
|
|
during or after a call to **notcurses_stop**. If a thread is always sitting
|
2020-01-02 03:39:16 +00:00
|
|
|
on blocking input, it can be tricky to guarantee that this doesn't happen.
|
|
|
|
|
2020-02-19 01:03:20 +00:00
|
|
|
Only one thread may call into the input stack at once, but unlike almost every
|
2021-07-25 04:38:33 +00:00
|
|
|
other function in notcurses, **notcurses_get** and friends can be called
|
2020-02-19 01:03:20 +00:00
|
|
|
concurrently with **notcurses_render**.
|
|
|
|
|
2021-10-05 09:34:06 +00:00
|
|
|
Do not simply **poll** the file descriptor associated with **stdin** to test
|
|
|
|
for input readiness. Instead, use the file descriptor returned by
|
|
|
|
**notcurses_inputready_fd** to ensure compatibility with future versions of
|
|
|
|
Notcurses (it is possible that future versions will process input in their own
|
|
|
|
contexts).
|
2020-05-02 16:56:39 +00:00
|
|
|
|
2021-08-31 19:47:21 +00:00
|
|
|
When support is detected, the Kitty keyboard disambiguation protocol will be
|
|
|
|
requested. This eliminates most of the **BUGS** mentioned below.
|
|
|
|
|
2021-11-09 09:16:23 +00:00
|
|
|
The full list of synthesized events is available in **<notcurses/nckeys.h>**.
|
|
|
|
|
2020-01-02 03:39:16 +00:00
|
|
|
# BUGS
|
|
|
|
|
2021-11-05 12:32:35 +00:00
|
|
|
The Shift key is not indicated in conjunction with typical Unicode text.
|
|
|
|
If e.g. Shift is used to generate a capital letter 'A', ***id*** will equal 'A',
|
|
|
|
and ***shift*** will be **false**. Similarly, when Ctrl is pressed along with a
|
|
|
|
letter, the letter will currently always be reported in its uppercase form.
|
|
|
|
E.g., if Shift, Ctrl, and 'a' are all pressed, this is indistinguishable from
|
|
|
|
Ctrl and 'A'.
|
2020-02-12 18:13:03 +00:00
|
|
|
|
2021-09-20 01:01:40 +00:00
|
|
|
Ctrl pressed along with 'J' or 'M', whether Shift is pressed or not,
|
|
|
|
currently registers as **NCKEY_ENTER**. This will likely change in the
|
|
|
|
future.
|
2020-02-12 03:44:45 +00:00
|
|
|
|
2021-09-20 01:01:40 +00:00
|
|
|
When the Kitty keyboard disambiguation protocol is used, most of these
|
2021-11-05 12:32:35 +00:00
|
|
|
issues are resolved. You can determine whether the protocol is in use
|
|
|
|
by examining the output of **notcurses-info(1)**. If the **kbd** property
|
|
|
|
is indicated, you're using the Kitty protocol.
|
2021-08-31 19:47:21 +00:00
|
|
|
|
2021-11-09 05:53:30 +00:00
|
|
|
Mouse events in the left margins will never be delivered to the
|
2021-10-05 09:34:06 +00:00
|
|
|
application (as is intended), but mouse events in the bottom and right margins
|
|
|
|
sometimes can be if the event occurs prior to a window resize.
|
|
|
|
|
2021-11-05 12:32:35 +00:00
|
|
|
The ***ypx*** and ***xpx*** fields are never currently valid (i.e. they are
|
|
|
|
always -1). This ought be fixed in the future using the SGR PixelMode mouse
|
|
|
|
protocol.
|
|
|
|
|
2021-10-26 13:59:33 +00:00
|
|
|
On some operating systems, **CLOCK_REALTIME** is used as the basis for
|
|
|
|
timeouts instead of **CLOCK_MONOTONIC**. This ought be fixed.
|
|
|
|
|
2020-01-02 02:23:11 +00:00
|
|
|
# SEE ALSO
|
|
|
|
|
2021-11-05 12:32:35 +00:00
|
|
|
**notcurses-info(1)**,
|
2021-10-26 13:59:33 +00:00
|
|
|
**clock_gettime(2)**,
|
2020-02-12 03:44:45 +00:00
|
|
|
**poll(2)**,
|
|
|
|
**notcurses(3)**,
|
2020-04-08 09:39:41 +00:00
|
|
|
**notcurses_refresh(3)**,
|
2020-02-19 01:03:20 +00:00
|
|
|
**notcurses_render(3)**,
|
2020-02-12 03:44:45 +00:00
|
|
|
**termios(3)**,
|
|
|
|
**terminfo(5)**,
|
|
|
|
**ascii(7)**,
|
|
|
|
**signal(7)**,
|
|
|
|
**unicode(7)**
|