Revert "[nckeys] move from PUA-B to 'plane 18' #2247"

This reverts commit e83f1f5ba3.
This commit is contained in:
nick black 2021-10-09 11:07:26 -04:00
parent e83f1f5ba3
commit 2148bcc4f2
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
9 changed files with 191 additions and 161 deletions

View File

@ -1,13 +1,6 @@
This document attempts to list user-visible changes and any major internal
rearrangements of Notcurses.
* 3.0.0 (not yet released) **"In the A"**
* **ABI3!** You will need a recompile, and possibly to update your code.
* The synthesized keys have been moved past Unicode's 17th plane, freeing
up the Private Use Area-B for clients. **nckey_suppuable_p()** has been
removed, as it's no longer relevant. **nckey_synthesized_p()** has been
added, as it now is.
* 2.4.6 (not yet released)
* Features 1, 2, and 8 of the Kitty keyboard protocol are now supported. This
provides much more detailed and fine-grained keyboard reports, including

View File

@ -623,13 +623,56 @@ must be readable without delay for it to be interpreted as such.
// returned to indicate that no input was available. Otherwise (including on
// EOF) (uint32_t)-1 is returned.
#define beyondunicode(w) ((w) + 0x100000)
#define suppuabize(w) ((w) + 0x100000)
// the special key definitions can be found in `<notcurses/nckeys.h>`
// Special composed key definitions. These values are added to 0x100000.
#define NCKEY_INVALID suppuabize(0)
#define NCKEY_RESIZE suppuabize(1) // generated internally in response to SIGWINCH
#define NCKEY_UP suppuabize(2)
#define NCKEY_RIGHT suppuabize(3)
#define NCKEY_DOWN suppuabize(4)
#define NCKEY_LEFT suppuabize(5)
#define NCKEY_INS suppuabize(6)
#define NCKEY_DEL suppuabize(7)
#define NCKEY_BACKSPACE suppuabize(8) // backspace (sometimes)
#define NCKEY_PGDOWN suppuabize(9)
#define NCKEY_PGUP suppuabize(10)
#define NCKEY_HOME suppuabize(11)
#define NCKEY_END suppuabize(12)
#define NCKEY_F00 suppuabize(20)
#define NCKEY_F01 suppuabize(21)
#define NCKEY_F02 suppuabize(22)
#define NCKEY_F03 suppuabize(23)
#define NCKEY_F04 suppuabize(24)
// ... up to 100 function keys, egads
#define NCKEY_ENTER suppuabize(121)
#define NCKEY_CLS suppuabize(122) // "clear-screen or erase"
#define NCKEY_DLEFT suppuabize(123) // down + left on keypad
#define NCKEY_DRIGHT suppuabize(124)
#define NCKEY_ULEFT suppuabize(125) // up + left on keypad
#define NCKEY_URIGHT suppuabize(126)
#define NCKEY_CENTER suppuabize(127) // the most truly neutral of keypresses
#define NCKEY_BEGIN suppuabize(128)
#define NCKEY_CANCEL suppuabize(129)
#define NCKEY_CLOSE suppuabize(130)
#define NCKEY_COMMAND suppuabize(131)
#define NCKEY_COPY suppuabize(132)
#define NCKEY_EXIT suppuabize(133)
#define NCKEY_PRINT suppuabize(134)
#define NCKEY_REFRESH suppuabize(135)
// Mouse events. We try to encode some details into the uint32_t (i.e. which
// button was pressed), but some is embedded in the ncinput event. The release
// event is generic across buttons; callers must maintain state, if they care.
#define NCKEY_BUTTON1 suppuabize(201)
#define NCKEY_BUTTON2 suppuabize(202)
#define NCKEY_BUTTON3 suppuabize(203)
// ... up to 11 mouse buttons
#define NCKEY_EOF suppuabize(300)
// Is this uint32_t a Supplementary Private Use Area-B codepoint?
static inline bool
nckey_synthesized_p(uint32_t w){
return w >= 0x110000 && w != (uint32_t)-1;
nckey_supppuab_p(uint32_t w){
return w >= 0x100000 && w <= 0x10fffd;
}
// An input event. Cell coordinates are currently defined only for mouse events.

View File

@ -32,8 +32,6 @@ typedef struct ncinput {
**bool nckey_mouse_p(uint32_t ***r***);**
**bool nckey_synthesized_p(uint32_t ***r***);**
**bool ncinput_nomod_p(const ncinput* ***ni***);**
**uint32_t notcurses_get(struct notcurses* ***n***, const struct timespec* ***ts***, ncinput* ***ni***);**
@ -153,9 +151,6 @@ does **notcurses_mouse_disable**.
the same input (though not necessarily the same input event), and
**false** otherwise.
**nckey_synthesized_p** returns **true** if ***r*** is greater than 0x10ffff
(the maximum Unicode codepoint), and not equal to **(uint32_t)-1**.
# NOTES
Like any other notcurses function, it is an error to call **notcurses_get**

View File

@ -117,9 +117,9 @@ namespace ncpp
return nckey_mouse_p (ch);
}
static bool IsSynthesized (char32_t ch) noexcept
static bool IsSuppUAB (char32_t ch) noexcept
{
return nckey_synthesized_p (ch);
return nckey_supppuab_p (ch);
}
};

View File

@ -5,154 +5,152 @@
extern "C" {
#endif
// we place our synthesized codepoints beyond the reach of Unicode's 17
// possible planes (limit due to UTF16). this way, none of our synthesized
// keys ought map to a real unicode character.
#define beyondunicode(w) ((w) + 0x110000)
#define suppuabize(w) ((w) + 0x100000)
#define NCKEY_INVALID beyondunicode(0)
#define NCKEY_SIGNAL beyondunicode(1) // we received either SIGWINCH or SIGCONT
#define NCKEY_UP beyondunicode(2)
#define NCKEY_RIGHT beyondunicode(3)
#define NCKEY_DOWN beyondunicode(4)
#define NCKEY_LEFT beyondunicode(5)
#define NCKEY_INS beyondunicode(6)
#define NCKEY_DEL beyondunicode(7)
#define NCKEY_BACKSPACE beyondunicode(8) // backspace (sometimes)
#define NCKEY_PGDOWN beyondunicode(9)
#define NCKEY_PGUP beyondunicode(10)
#define NCKEY_HOME beyondunicode(11)
#define NCKEY_END beyondunicode(12)
#define NCKEY_F00 beyondunicode(20)
#define NCKEY_F01 beyondunicode(21)
#define NCKEY_F02 beyondunicode(22)
#define NCKEY_F03 beyondunicode(23)
#define NCKEY_F04 beyondunicode(24)
#define NCKEY_F05 beyondunicode(25)
#define NCKEY_F06 beyondunicode(26)
#define NCKEY_F07 beyondunicode(27)
#define NCKEY_F08 beyondunicode(28)
#define NCKEY_F09 beyondunicode(29)
#define NCKEY_F10 beyondunicode(30)
#define NCKEY_F11 beyondunicode(31)
#define NCKEY_F12 beyondunicode(32)
#define NCKEY_F13 beyondunicode(33)
#define NCKEY_F14 beyondunicode(34)
#define NCKEY_F15 beyondunicode(35)
#define NCKEY_F16 beyondunicode(36)
#define NCKEY_F17 beyondunicode(37)
#define NCKEY_F18 beyondunicode(38)
#define NCKEY_F19 beyondunicode(39)
#define NCKEY_F20 beyondunicode(40)
#define NCKEY_F21 beyondunicode(41)
#define NCKEY_F22 beyondunicode(42)
#define NCKEY_F23 beyondunicode(43)
#define NCKEY_F24 beyondunicode(44)
#define NCKEY_F25 beyondunicode(45)
#define NCKEY_F26 beyondunicode(46)
#define NCKEY_F27 beyondunicode(47)
#define NCKEY_F28 beyondunicode(48)
#define NCKEY_F29 beyondunicode(49)
#define NCKEY_F30 beyondunicode(50)
#define NCKEY_F31 beyondunicode(51)
#define NCKEY_F32 beyondunicode(52)
#define NCKEY_F33 beyondunicode(53)
#define NCKEY_F34 beyondunicode(54)
#define NCKEY_F35 beyondunicode(55)
#define NCKEY_F36 beyondunicode(56)
#define NCKEY_F37 beyondunicode(57)
#define NCKEY_F38 beyondunicode(58)
#define NCKEY_F39 beyondunicode(59)
#define NCKEY_F40 beyondunicode(60)
#define NCKEY_F41 beyondunicode(61)
#define NCKEY_F42 beyondunicode(62)
#define NCKEY_F43 beyondunicode(63)
#define NCKEY_F44 beyondunicode(64)
#define NCKEY_F45 beyondunicode(65)
#define NCKEY_F46 beyondunicode(66)
#define NCKEY_F47 beyondunicode(67)
#define NCKEY_F48 beyondunicode(68)
#define NCKEY_F49 beyondunicode(69)
#define NCKEY_F50 beyondunicode(70)
#define NCKEY_F51 beyondunicode(71)
#define NCKEY_F52 beyondunicode(72)
#define NCKEY_F53 beyondunicode(73)
#define NCKEY_F54 beyondunicode(74)
#define NCKEY_F55 beyondunicode(75)
#define NCKEY_F56 beyondunicode(76)
#define NCKEY_F57 beyondunicode(77)
#define NCKEY_F58 beyondunicode(78)
#define NCKEY_F59 beyondunicode(79)
#define NCKEY_F60 beyondunicode(80)
// Special composed key definitions. These values are added to 0x100000.
#define NCKEY_INVALID suppuabize(0)
#define NCKEY_SIGNAL suppuabize(1) // we received either SIGWINCH or SIGCONT
#define NCKEY_UP suppuabize(2)
#define NCKEY_RIGHT suppuabize(3)
#define NCKEY_DOWN suppuabize(4)
#define NCKEY_LEFT suppuabize(5)
#define NCKEY_INS suppuabize(6)
#define NCKEY_DEL suppuabize(7)
#define NCKEY_BACKSPACE suppuabize(8) // backspace (sometimes)
#define NCKEY_PGDOWN suppuabize(9)
#define NCKEY_PGUP suppuabize(10)
#define NCKEY_HOME suppuabize(11)
#define NCKEY_END suppuabize(12)
#define NCKEY_F00 suppuabize(20)
#define NCKEY_F01 suppuabize(21)
#define NCKEY_F02 suppuabize(22)
#define NCKEY_F03 suppuabize(23)
#define NCKEY_F04 suppuabize(24)
#define NCKEY_F05 suppuabize(25)
#define NCKEY_F06 suppuabize(26)
#define NCKEY_F07 suppuabize(27)
#define NCKEY_F08 suppuabize(28)
#define NCKEY_F09 suppuabize(29)
#define NCKEY_F10 suppuabize(30)
#define NCKEY_F11 suppuabize(31)
#define NCKEY_F12 suppuabize(32)
#define NCKEY_F13 suppuabize(33)
#define NCKEY_F14 suppuabize(34)
#define NCKEY_F15 suppuabize(35)
#define NCKEY_F16 suppuabize(36)
#define NCKEY_F17 suppuabize(37)
#define NCKEY_F18 suppuabize(38)
#define NCKEY_F19 suppuabize(39)
#define NCKEY_F20 suppuabize(40)
#define NCKEY_F21 suppuabize(41)
#define NCKEY_F22 suppuabize(42)
#define NCKEY_F23 suppuabize(43)
#define NCKEY_F24 suppuabize(44)
#define NCKEY_F25 suppuabize(45)
#define NCKEY_F26 suppuabize(46)
#define NCKEY_F27 suppuabize(47)
#define NCKEY_F28 suppuabize(48)
#define NCKEY_F29 suppuabize(49)
#define NCKEY_F30 suppuabize(50)
#define NCKEY_F31 suppuabize(51)
#define NCKEY_F32 suppuabize(52)
#define NCKEY_F33 suppuabize(53)
#define NCKEY_F34 suppuabize(54)
#define NCKEY_F35 suppuabize(55)
#define NCKEY_F36 suppuabize(56)
#define NCKEY_F37 suppuabize(57)
#define NCKEY_F38 suppuabize(58)
#define NCKEY_F39 suppuabize(59)
#define NCKEY_F40 suppuabize(60)
#define NCKEY_F41 suppuabize(61)
#define NCKEY_F42 suppuabize(62)
#define NCKEY_F43 suppuabize(63)
#define NCKEY_F44 suppuabize(64)
#define NCKEY_F45 suppuabize(65)
#define NCKEY_F46 suppuabize(66)
#define NCKEY_F47 suppuabize(67)
#define NCKEY_F48 suppuabize(68)
#define NCKEY_F49 suppuabize(69)
#define NCKEY_F50 suppuabize(70)
#define NCKEY_F51 suppuabize(71)
#define NCKEY_F52 suppuabize(72)
#define NCKEY_F53 suppuabize(73)
#define NCKEY_F54 suppuabize(74)
#define NCKEY_F55 suppuabize(75)
#define NCKEY_F56 suppuabize(76)
#define NCKEY_F57 suppuabize(77)
#define NCKEY_F58 suppuabize(78)
#define NCKEY_F59 suppuabize(79)
#define NCKEY_F60 suppuabize(80)
// ... leave room for up to 100 function keys, egads
#define NCKEY_ENTER beyondunicode(121)
#define NCKEY_CLS beyondunicode(122) // "clear-screen or erase"
#define NCKEY_DLEFT beyondunicode(123) // down + left on keypad
#define NCKEY_DRIGHT beyondunicode(124)
#define NCKEY_ULEFT beyondunicode(125) // up + left on keypad
#define NCKEY_URIGHT beyondunicode(126)
#define NCKEY_CENTER beyondunicode(127) // the most truly neutral of keypresses
#define NCKEY_BEGIN beyondunicode(128)
#define NCKEY_CANCEL beyondunicode(129)
#define NCKEY_CLOSE beyondunicode(130)
#define NCKEY_COMMAND beyondunicode(131)
#define NCKEY_COPY beyondunicode(132)
#define NCKEY_EXIT beyondunicode(133)
#define NCKEY_PRINT beyondunicode(134)
#define NCKEY_REFRESH beyondunicode(135)
#define NCKEY_ENTER suppuabize(121)
#define NCKEY_CLS suppuabize(122) // "clear-screen or erase"
#define NCKEY_DLEFT suppuabize(123) // down + left on keypad
#define NCKEY_DRIGHT suppuabize(124)
#define NCKEY_ULEFT suppuabize(125) // up + left on keypad
#define NCKEY_URIGHT suppuabize(126)
#define NCKEY_CENTER suppuabize(127) // the most truly neutral of keypresses
#define NCKEY_BEGIN suppuabize(128)
#define NCKEY_CANCEL suppuabize(129)
#define NCKEY_CLOSE suppuabize(130)
#define NCKEY_COMMAND suppuabize(131)
#define NCKEY_COPY suppuabize(132)
#define NCKEY_EXIT suppuabize(133)
#define NCKEY_PRINT suppuabize(134)
#define NCKEY_REFRESH suppuabize(135)
// these keys aren't generally available outside of the kitty protocol
#define NCKEY_CAPS_LOCK beyondunicode(150)
#define NCKEY_SCROLL_LOCK beyondunicode(151)
#define NCKEY_NUM_LOCK beyondunicode(152)
#define NCKEY_PRINT_SCREEN beyondunicode(153)
#define NCKEY_PAUSE beyondunicode(154)
#define NCKEY_MENU beyondunicode(155)
#define NCKEY_CAPS_LOCK suppuabize(150)
#define NCKEY_SCROLL_LOCK suppuabize(151)
#define NCKEY_NUM_LOCK suppuabize(152)
#define NCKEY_PRINT_SCREEN suppuabize(153)
#define NCKEY_PAUSE suppuabize(154)
#define NCKEY_MENU suppuabize(155)
// media keys, similarly only available through kitty's protocol
#define NCKEY_MEDIA_PLAY beyondunicode(158)
#define NCKEY_MEDIA_PAUSE beyondunicode(159)
#define NCKEY_MEDIA_PPAUSE beyondunicode(160)
#define NCKEY_MEDIA_REV beyondunicode(161)
#define NCKEY_MEDIA_STOP beyondunicode(162)
#define NCKEY_MEDIA_FF beyondunicode(163)
#define NCKEY_MEDIA_REWIND beyondunicode(164)
#define NCKEY_MEDIA_NEXT beyondunicode(165)
#define NCKEY_MEDIA_PREV beyondunicode(166)
#define NCKEY_MEDIA_RECORD beyondunicode(167)
#define NCKEY_MEDIA_LVOL beyondunicode(168)
#define NCKEY_MEDIA_RVOL beyondunicode(169)
#define NCKEY_MEDIA_MUTE beyondunicode(170)
#define NCKEY_MEDIA_PLAY suppuabize(158)
#define NCKEY_MEDIA_PAUSE suppuabize(159)
#define NCKEY_MEDIA_PPAUSE suppuabize(160)
#define NCKEY_MEDIA_REV suppuabize(161)
#define NCKEY_MEDIA_STOP suppuabize(162)
#define NCKEY_MEDIA_FF suppuabize(163)
#define NCKEY_MEDIA_REWIND suppuabize(164)
#define NCKEY_MEDIA_NEXT suppuabize(165)
#define NCKEY_MEDIA_PREV suppuabize(166)
#define NCKEY_MEDIA_RECORD suppuabize(167)
#define NCKEY_MEDIA_LVOL suppuabize(168)
#define NCKEY_MEDIA_RVOL suppuabize(169)
#define NCKEY_MEDIA_MUTE suppuabize(170)
// modifiers when pressed by themselves. this ordering comes from the Kitty
// keyboard protocol, and mustn't be changed without updating handlers.
#define NCKEY_LSHIFT beyondunicode(171)
#define NCKEY_LCTRL beyondunicode(172)
#define NCKEY_LALT beyondunicode(173)
#define NCKEY_LSUPER beyondunicode(174)
#define NCKEY_LHYPER beyondunicode(175)
#define NCKEY_LMETA beyondunicode(176)
#define NCKEY_RSHIFT beyondunicode(177)
#define NCKEY_RCTRL beyondunicode(178)
#define NCKEY_RALT beyondunicode(179)
#define NCKEY_RSUPER beyondunicode(180)
#define NCKEY_RHYPER beyondunicode(181)
#define NCKEY_RMETA beyondunicode(182)
#define NCKEY_LSHIFT suppuabize(171)
#define NCKEY_LCTRL suppuabize(172)
#define NCKEY_LALT suppuabize(173)
#define NCKEY_LSUPER suppuabize(174)
#define NCKEY_LHYPER suppuabize(175)
#define NCKEY_LMETA suppuabize(176)
#define NCKEY_RSHIFT suppuabize(177)
#define NCKEY_RCTRL suppuabize(178)
#define NCKEY_RALT suppuabize(179)
#define NCKEY_RSUPER suppuabize(180)
#define NCKEY_RHYPER suppuabize(181)
#define NCKEY_RMETA suppuabize(182)
// mouse events. We try to encode some details into the char32_t (i.e. which
// button was pressed), but some is embedded in the ncinput event. the release
// event is generic across buttons; callers must maintain state, if they care.
#define NCKEY_BUTTON1 beyondunicode(201)
#define NCKEY_BUTTON2 beyondunicode(202)
#define NCKEY_BUTTON3 beyondunicode(203)
#define NCKEY_BUTTON4 beyondunicode(204) // scrollwheel up
#define NCKEY_BUTTON5 beyondunicode(205) // scrollwheel down
#define NCKEY_BUTTON6 beyondunicode(206)
#define NCKEY_BUTTON7 beyondunicode(207)
#define NCKEY_BUTTON8 beyondunicode(208)
#define NCKEY_BUTTON9 beyondunicode(209)
#define NCKEY_BUTTON10 beyondunicode(210)
#define NCKEY_BUTTON11 beyondunicode(211)
#define NCKEY_BUTTON1 suppuabize(201)
#define NCKEY_BUTTON2 suppuabize(202)
#define NCKEY_BUTTON3 suppuabize(203)
#define NCKEY_BUTTON4 suppuabize(204) // scrollwheel up
#define NCKEY_BUTTON5 suppuabize(205) // scrollwheel down
#define NCKEY_BUTTON6 suppuabize(206)
#define NCKEY_BUTTON7 suppuabize(207)
#define NCKEY_BUTTON8 suppuabize(208)
#define NCKEY_BUTTON9 suppuabize(209)
#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 beyondunicode(300)
#define NCKEY_EOF suppuabize(300)
// Synonyms (so far as we're concerned)
#define NCKEY_SCROLL_UP NCKEY_BUTTON4

View File

@ -1018,8 +1018,8 @@ API void notcurses_drop_planes(struct notcurses* nc);
// Unicode codepoint, *not* an entire Extended Grapheme Cluster. It is also
// possible that we will read a special keypress, i.e. anything that doesn't
// correspond to a Unicode codepoint (e.g. arrow keys, function keys, screen
// resize events, etc.). These are mapped past Unicode's 17th plane, starting
// at U+110000. See <notcurses/nckeys.h>.
// resize events, etc.). These are mapped into Unicode's Supplementary
// Private Use Area-B, starting at U+100000. See <notcurses/nckeys.h>.
//
// notcurses_getc_nblock() is nonblocking. notcurses_getc_blocking() blocks
// until a codepoint or special key is read, or until interrupted by a signal.
@ -1029,9 +1029,10 @@ API void notcurses_drop_planes(struct notcurses* nc);
// returned to indicate that no input was available. Otherwise (including on
// EOF) (uint32_t)-1 is returned.
// Is this uint32_t a Supplementary Private Use Area-B codepoint?
static inline bool
nckey_synthesized_p(uint32_t r){
return r >= 0x110000 && r != (uint32_t)-1;
nckey_supppuab_p(uint32_t w){
return w >= 0x100000 && w <= 0x10fffd;
}
// Is the event a synthesized mouse event?

View File

@ -334,7 +334,7 @@ int input_demo(ncpp::NotCurses* nc) {
break;
}
}else{
if(nckey_synthesized_p(r)){
if(nckey_supppuab_p(r)){
n->set_fg_rgb8(250, 64, 128);
if(n->printf("Special: [0x%02x (%02d)] '%s'", r, r, nckeystr(r)) < 0){
break;

View File

@ -1025,7 +1025,7 @@ char* ncdirect_readline(ncdirect* n, const char* prompt){
wpos = 1;
}else if(id == 'e' && ni.ctrl){
wpos = wused - 1;
}else if(nckey_synthesized_p(ni.id)){
}else if(nckey_supppuab_p(ni.id)){
continue;
}else{
if(wspace - 1 < wused){

View File

@ -368,7 +368,7 @@ bool ncreader_offer_input(ncreader* n, const ncinput* ni){
}else if(ni->id == NCKEY_DOWN){
ncreader_move_down(n);
return true;
}else if(nckey_synthesized_p(ni->id)){
}else if(nckey_supppuab_p(ni->id)){
return false;
}
// FIXME need to collect full EGCs