This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch tymux-10-quiet-head
in repository terminology.

View the commit online.

commit e0d74ae8dfc4cb5dd6379df9b4ac27c02fca88a8
Author: Boris Faure <[email protected]>
AuthorDate: Sat Nov 14 21:32:06 2026 +0000

    keyin: add the numLock mode (?1035)
    
    The private mode ?1035, numLock, decides between the keyboard's
    Num_Lock and application keypad mode (DECPAM, ESC =, from the VT100
    User Guide). Set, the default, a locked keypad keeps sending the
    digits, which is what a program reading numbers inside an ncurses
    application expects. Reset (CSI ? 1035 l), DECPAM wins: the keypad
    sends the SS3 application-keypad forms (\033Ow for KP_7, \033OM for
    KP_Enter), whatever the state of Num_Lock.
    
    DECRQM reports the mode. DECSTR and RIS restore the default: a reset
    returns every keyboard mode to its default, so a program that wants
    DECPAM to win has to reset ?1035 again after one.
---
 src/bin/keyin_encode.c | 28 ++++++++----------
 src/bin/termpty.c      | 10 +++++++
 src/bin/termpty.h      |  1 +
 src/bin/termptyesc.c   |  6 ++++
 src/bin/termptyops.c   |  1 +
 src/bin/tytest.c       |  1 +
 src/bin/tytest_keyin.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++---
 src/bin/unit_tests.h   |  1 +
 tests/numlock-mode.sh  | 13 ++++++++
 tests/tests.results    |  1 +
 10 files changed, 123 insertions(+), 19 deletions(-)

diff --git a/src/bin/keyin_encode.c b/src/bin/keyin_encode.c
index 2db88f26..e81adf77 100644
--- a/src/bin/keyin_encode.c
+++ b/src/bin/keyin_encode.c
@@ -281,22 +281,20 @@ keyin_encode_key(Termpty *ty, const char *key, const char *string,
      }
    if (!strncmp(key, "KP_", 3))
      {
-        if (!numlock)
+        /* ?1035, numLock, default set: Num_Lock overrides DECPAM */
+        if (ty->termstate.alt_kp && !(ty->termstate.numlock_mode && numlock))
           {
-             if (ty->termstate.alt_kp)
-               {
-                  if (_key_try(ty, tty_keys_kp_app,
-                               sizeof(tty_keys_kp_app)/sizeof(tty_keys_kp_app[0]),
-                               key, alt, shift, ctrl))
-                    return;
-               }
-             else
-               {
-                  if (_key_try(ty, tty_keys_kp_plain,
-                               sizeof(tty_keys_kp_plain)/sizeof(tty_keys_kp_plain[0]),
-                               key, alt, shift, ctrl))
-                    return;
-               }
+             if (_key_try(ty, tty_keys_kp_app,
+                          sizeof(tty_keys_kp_app)/sizeof(tty_keys_kp_app[0]),
+                          key, alt, shift, ctrl))
+               return;
+          }
+        else if (!numlock)
+          {
+             if (_key_try(ty, tty_keys_kp_plain,
+                          sizeof(tty_keys_kp_plain)/sizeof(tty_keys_kp_plain[0]),
+                          key, alt, shift, ctrl))
+               return;
           }
      }
    else
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index f8445a65..579854fc 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -3267,6 +3267,16 @@ tytest_decrqm(void)
    _ty_feed(&ty, "\x1b[?1004$p");
    _ty_reply_is(&ty, "\x1b[?1004;1$y");
 
+   _ty_feed(&ty, "\x1b[?1035$p");
+   _ty_reply_is(&ty, "\x1b[?1035;1$y");
+   _ty_feed(&ty, "\x1b[?1035l\x1b[?1035$p");
+   _ty_reply_is(&ty, "\x1b[?1035;2$y");
+   /* DECSTR and RIS restore the default */
+   _ty_feed(&ty, "\x1b[?1035l\x1b[!p\x1b[?1035$p");
+   _ty_reply_is(&ty, "\x1b[?1035;1$y");
+   _ty_feed(&ty, "\x1b[?1035l\x1b" "c\x1b[?1035$p");
+   _ty_reply_is(&ty, "\x1b[?1035;1$y");
+
    _ty_feed(&ty, "\x1b[?2$p\x1b[?4$p\x1b[?2027$p");
    _ty_reply_is(&ty, "\x1b[?2;3$y\x1b[?4;4$y\x1b[?2027;4$y");
 
diff --git a/src/bin/termpty.h b/src/bin/termpty.h
index 3dfb6bf9..9e0ad4a8 100644
--- a/src/bin/termpty.h
+++ b/src/bin/termpty.h
@@ -155,6 +155,7 @@ typedef struct tag_Term_State {
     unsigned int  restrict_cursor : 1;
     unsigned int  multibyte : 1;
     unsigned int  alt_kp : 1;
+    unsigned int  numlock_mode : 1;
     unsigned int  insert : 1;
     unsigned int  appcursor : 1;
     unsigned int  wrap : 1;
diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index f9893107..b20a5458 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -695,6 +695,10 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, Eina_Unicode *b,
                       */
                    WRN("Ignored screen mode %i", arg);
                    break;
+                case 1035:
+                   DBG("%s numLock mode", mode ? "enable" : "disable");
+                   ty->termstate.numlock_mode = mode;
+                   break;
                 case 1047:
                    if (!mode && ty->altbuf)
                      /* clear screen before switching back to normal */
@@ -892,6 +896,8 @@ _dec_private_mode_status(const Termpty *ty, int mode)
          return DECRPM_NOT_RECOGNIZED;
       case 1034: /* eightBitInput: Alt always sends ESC */
          return DECRPM_PERMANENTLY_RESET;
+      case 1035: /* numLock: set, Num_Lock overrides DECPAM */
+         return _decrpm_from_bool(ty->termstate.numlock_mode);
       case 1047:
          return _decrpm_from_bool(ty->altbuf);
       case 1048: /* save cursor is an action, there is no state to report */
diff --git a/src/bin/termptyops.c b/src/bin/termptyops.c
index a6a48348..68513a70 100644
--- a/src/bin/termptyops.c
+++ b/src/bin/termptyops.c
@@ -740,6 +740,7 @@ termpty_soft_reset_state(Termpty *ty)
    ty->termstate.chset[3] = 'B';
    ty->termstate.multibyte = 0;
    ty->termstate.alt_kp = 0;
+   ty->termstate.numlock_mode = 1;
    ty->termstate.insert = 0;
    ty->termstate.appcursor = 0;
    ty->termstate.wrap = 1;
diff --git a/src/bin/tytest.c b/src/bin/tytest.c
index a5fedefc..b0113594 100644
--- a/src/bin/tytest.c
+++ b/src/bin/tytest.c
@@ -98,6 +98,7 @@ static struct {
        { "keyin_modify_other_keys", tytest_keyin_modify_other_keys},
        { "keyin_modify_other_keys_level1", tytest_keyin_modify_other_keys_level1},
        { "keyin_backspace", tytest_keyin_backspace},
+       { "keyin_keypad", tytest_keyin_keypad},
        { "config_erase_is_del_upgrade", tytest_config_erase_is_del_upgrade},
        { "vs16_regression_no_scroll", tytest_vs16_regression_no_scroll},
        { "vs16_bare_narrow", tytest_vs16_bare_narrow},
diff --git a/src/bin/tytest_keyin.c b/src/bin/tytest_keyin.c
index ab87e0ea..3d639656 100644
--- a/src/bin/tytest_keyin.c
+++ b/src/bin/tytest_keyin.c
@@ -60,7 +60,7 @@ _show(const char *s, size_t len)
 
 /* Press a key and compare every byte it put on the pty. */
 static int
-_press_is(const char *key, const char *string,
+_press_is(const char *key, Eina_Bool numlock, const char *string,
           int alt, int shift, int ctrl,
           const char *expected, size_t expected_len)
 {
@@ -68,7 +68,7 @@ _press_is(const char *key, const char *string,
    int bad = 0;
 
    ty_sb_free(sb);
-   keyin_encode_key(_ty, key, string, EINA_FALSE, alt, shift, ctrl);
+   keyin_encode_key(_ty, key, string, numlock, alt, shift, ctrl);
 
    if ((sb->len != expected_len) ||
        memcmp(sb->buf + sb->gap, expected, expected_len))
@@ -88,11 +88,15 @@ _press_is(const char *key, const char *string,
 
 /* For a named key, where ev->string is never reached. */
 #define PRESS(Key, Alt, Shift, Ctrl, Expected) \
-   bad += _press_is(Key, NULL, Alt, Shift, Ctrl, Expected, sizeof(Expected) - 1)
+   bad += _press_is(Key, EINA_FALSE, NULL, Alt, Shift, Ctrl, Expected, sizeof(Expected) - 1)
 
 /* For an ordinary character, with the ev->string evas would deliver. */
 #define PRESS_S(Key, String, Alt, Shift, Ctrl, Expected) \
-   bad += _press_is(Key, String, Alt, Shift, Ctrl, Expected, sizeof(Expected) - 1)
+   bad += _press_is(Key, EINA_FALSE, String, Alt, Shift, Ctrl, Expected, sizeof(Expected) - 1)
+
+/* For a keypad key, where Num_Lock is a dimension of the case. */
+#define PRESS_KP(Key, Numlock, String, Alt, Shift, Ctrl, Expected) \
+   bad += _press_is(Key, Numlock, String, Alt, Shift, Ctrl, Expected, sizeof(Expected) - 1)
 
 /* Legacy encoding, i.e. modifyOtherKeys off. */
 int
@@ -311,7 +315,75 @@ tytest_keyin_backspace(void)
    return bad;
 }
 
+/* Keypad keys under DECPAM (\033=) and Num_Lock: the numLock mode
+ * (?1035) decides which of the two wins. */
+int
+tytest_keyin_keypad(void)
+{
+   int bad = 0;
+
+   _init();
+
+   /* ?1035 set, the default: Num_Lock wins, the digits come from
+    * ev->string, whatever DECPAM says */
+   _ty->termstate.numlock_mode = EINA_TRUE;
+   _ty->termstate.alt_kp = EINA_TRUE;
+   /*      key            nl string alt shift ctrl  expected */
+   PRESS_KP("KP_7",       1, "7",   0,  0,    0,    "7");
+   PRESS_KP("KP_Add",     1, "+",   0,  0,    0,    "+");
+   PRESS_KP("KP_Enter",   1, "\r",  0,  0,    0,    "\r");
+   _ty->termstate.alt_kp = EINA_FALSE;
+   PRESS_KP("KP_7",       1, "7",   0,  0,    0,    "7");
+
+   /* ?1035 reset, DECPAM set: DECPAM wins over Num_Lock, with the SS3
+    * forms the terminfo entry advertises (ka1=\EOw, kb2=\EOu, kc3=\EOs,
+    * kent=\EOM) */
+   _ty->termstate.numlock_mode = EINA_FALSE;
+   _ty->termstate.alt_kp = EINA_TRUE;
+   PRESS_KP("KP_7",       1, "7",   0,  0,    0,    "\033Ow");
+   PRESS_KP("KP_5",       1, "5",   0,  0,    0,    "\033Ou");
+   PRESS_KP("KP_3",       1, "3",   0,  0,    0,    "\033Os");
+   PRESS_KP("KP_1",       1, "1",   0,  0,    0,    "\033Oq");
+   PRESS_KP("KP_Enter",   1, "\r",  0,  0,    0,    "\033OM");
+   PRESS_KP("KP_Add",     1, "+",   0,  0,    0,    "\033Ok");
+   PRESS_KP("KP_Decimal", 1, ".",   0,  0,    0,    "\033On");
+   PRESS_KP("KP_7",       1, "7",   0,  1,    0,    "\033O2w");
+   PRESS_KP("KP_5",       1, "5",   0,  0,    1,    "\033O5u");
+
+   /* ?1035 reset, no DECPAM: Num_Lock keeps sending the digits */
+   _ty->termstate.alt_kp = EINA_FALSE;
+   PRESS_KP("KP_7",       1, "7",   0,  0,    0,    "7");
+
+   /* Num_Lock off: unchanged for either mode and either DECPAM state */
+   _ty->termstate.alt_kp = EINA_TRUE;
+   _ty->termstate.appcursor = EINA_TRUE;
+   PRESS_KP("KP_Home",    0, NULL,  0,  0,    0,    "\033OH");
+   PRESS_KP("KP_Begin",   0, NULL,  0,  0,    0,    "\033OE");
+   _ty->termstate.appcursor = EINA_FALSE;
+   PRESS_KP("KP_Next",    0, NULL,  0,  0,    0,    "\033[6~");
+   PRESS_KP("KP_Enter",   0, NULL,  0,  0,    0,    "\033OM");
+   PRESS_KP("KP_Add",     0, NULL,  0,  0,    0,    "\033Ok");
+
+   _ty->termstate.alt_kp = EINA_FALSE;
+   PRESS_KP("KP_Up",      0, NULL,  0,  0,    0,    "\033[A");
+   PRESS_KP("KP_Up",      0, NULL,  0,  1,    0,    "8");
+   _ty->termstate.appcursor = EINA_TRUE;
+   PRESS_KP("KP_Up",      0, NULL,  0,  0,    0,    "\033OA");
+   _ty->termstate.appcursor = EINA_FALSE;
+
+   /* ?1035 set again: Num_Lock off, DECPAM still wins */
+   _ty->termstate.numlock_mode = EINA_TRUE;
+   _ty->termstate.alt_kp = EINA_TRUE;
+   PRESS_KP("KP_7",       0, NULL,  0,  0,    0,    "\033Ow");
+
+   if (bad)
+     fprintf(stderr, "\n  %d wrong encoding%s", bad, bad == 1 ? "" : "s");
+   _shutdown();
+   return bad;
+}
+
 #undef PRESS
 #undef PRESS_S
+#undef PRESS_KP
 
 #endif
diff --git a/src/bin/unit_tests.h b/src/bin/unit_tests.h
index a65f768b..f5c9b6ea 100644
--- a/src/bin/unit_tests.h
+++ b/src/bin/unit_tests.h
@@ -99,4 +99,5 @@ int tytest_keyin_legacy(void);
 int tytest_keyin_modify_other_keys(void);
 int tytest_keyin_modify_other_keys_level1(void);
 int tytest_keyin_backspace(void);
+int tytest_keyin_keypad(void);
 int tytest_config_erase_is_del_upgrade(void);
diff --git a/tests/numlock-mode.sh b/tests/numlock-mode.sh
new file mode 100644
index 00000000..bf8c0375
--- /dev/null
+++ b/tests/numlock-mode.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+# shellcheck source=tests/utils.sh
+. "$(dirname "$0")/utils.sh"
+
+# the numLock mode (?1035): set (the default), Num_Lock forces the
+# numeric keypad even under DECPAM; reset, DECPAM wins
+printf '\033[?1035\044p'
+printf '\033[?1035l\033[?1035\044p'
+printf '\033[?1035h\033[?1035\044p'
+
+# DECSTR and RIS restore the default
+printf '\033[?1035l\033[!p\033[?1035\044p'
+printf '\033[?1035l\033c\033[?1035\044p'
diff --git a/tests/tests.results b/tests/tests.results
index 882af36c..986f4c41 100644
--- a/tests/tests.results
+++ b/tests/tests.results
@@ -33,6 +33,7 @@ dsr-udk.sh 542e6579a3744576cf07476ba620ea5c
 decrqm.sh 1f7b1ed07dfe2048e4c10a7c01035661
 decrqm-reset.sh df5394cbdee00974daf94118ef980f33
 decrqm-ansi.sh 226de63aab78c0a5fe9d1ed9e971d9d8
+numlock-mode.sh da914b1b01a036b360cea31af09681f0
 kam.sh c9cc4dfabd524bf45ad1d8d01b12ccb1
 decrqss-invalid.sh 55dc9457646511e1d78b87344d78a7a1
 decrqss-sgr.sh db9d3cb36b3b4bea61cee774d8d5e7bc

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to