]> Sergey Matveev's repositories - nnn.git/commitdiff
Fix #1428: handle unicode keybinds
authorArun Prakash Jana <engineerarun@gmail.com>
Wed, 20 Jul 2022 14:18:27 +0000 (19:48 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Wed, 20 Jul 2022 14:39:34 +0000 (20:09 +0530)
src/nnn.c
src/nnn.h

index a45e66df00acaeb412d438c7571ae2f90b84fe08..8116cb2b0c56efda2090c6b3c9437b43d7865d3b 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
 #define __USE_XOPEN_EXTENDED 1
 #endif
 #include <ftw.h>
-#include <wchar.h>
 #include <pwd.h>
 #include <grp.h>
 
@@ -1362,25 +1361,27 @@ static inline bool xconfirm(int c)
 
 static int get_input(const char *prompt)
 {
+       wint_t ch[1];
+
        if (prompt)
                printmsg(prompt);
        cleartimeout();
 
-       int r = getch();
+       get_wch(ch);
 
 #ifdef KEY_RESIZE
-       while (r == KEY_RESIZE) {
+       while (*ch == KEY_RESIZE) {
                if (prompt) {
                        clearoldprompt();
                        xlines = LINES;
                        printmsg(prompt);
                }
 
-               r = getch();
+               get_wch(ch);
        }
 #endif
        settimeout();
-       return r;
+       return (int)*ch;
 }
 
 static bool isselfileempty(void)
@@ -3010,13 +3011,13 @@ static int nextsel(int presel)
 #ifdef BENCH
        return SEL_QUIT;
 #endif
-       int c = presel;
-       uint_t i;
+       wint_t c = presel;
+       int i = ERR;
        bool escaped = FALSE;
 
        if (c == 0 || c == MSGWAIT) {
 try_quit:
-               c = getch();
+               i = get_wch(&c);
                //DPRINTF_D(c);
                //DPRINTF_S(keyname(c));
 
@@ -3028,8 +3029,8 @@ try_quit:
                /* Handle Alt+key */
                if (c == ESC) {
                        timeout(0);
-                       c = getch();
-                       if (c != ERR) {
+                       i = get_wch(&c);
+                       if (i != ERR) {
                                if (c == ESC)
                                        c = CONTROL('L');
                                else {
@@ -3051,14 +3052,14 @@ try_quit:
                        }
                }
 
-               if (c == ERR && presel == MSGWAIT)
+               if (i == ERR && presel == MSGWAIT)
                        c = (cfg.filtermode || filterset()) ? FILTER : CONTROL('L');
                else if (c == FILTER || c == CONTROL('L'))
                        /* Clear previous filter when manually starting */
                        clearfilter();
        }
 
-       if (c == -1) {
+       if (i == ERR) {
                ++idle;
 
                /*
index e603840f0ed708bb18f69383170ad81b350ff89a..85e11f2f48a7a943733faafe80f6267428dc7c2a 100644 (file)
--- a/src/nnn.h
+++ b/src/nnn.h
@@ -31,6 +31,7 @@
 #pragma once
 
 #include <curses.h>
+#include <wchar.h>
 
 #define CONTROL(c) ((c) & 0x1f)
 
@@ -121,7 +122,7 @@ enum action {
 
 /* Associate a pressed key to an action */
 struct key {
-       int sym;         /* Key pressed */
+       wint_t sym;      /* Key pressed */
        enum action act; /* Action */
 };