comparison src/readline-2-event-hook.patch @ 5031:5049ab5e66f6

Re-add readline patches to work with readline 8 (Bug #55957) * src/readline-1-display.patch, src/readline-1-input.patch, src/readline-1-sigwinch.patch, src/readline-2-event-hook.patch dist-files.mk: add refes to added files
author John Donoghue
date Thu, 21 Mar 2019 09:34:09 -0400
parents
children 41e50d658de0
comparison
equal deleted inserted replaced
5030:eec61a755122 5031:5049ab5e66f6
1 diff -ur readline-8.0.sigwinch/input.c readline-8.0/input.c
2 --- readline-8.0.sigwinch/input.c 2019-03-20 08:15:55.450361377 -0400
3 +++ readline-8.0/input.c 2019-03-20 08:30:58.059756179 -0400
4 @@ -140,6 +140,11 @@
5 static unsigned char ibuffer[512];
6 static int ibuffer_len = sizeof (ibuffer) - 1;
7
8 +#if defined (__MINGW32__)
9 +static int _win32_getch (void);
10 +static int _win32_kbhit (void);
11 +#endif
12 +
13 #define any_typein (push_index != pop_index)
14
15 int
16 @@ -266,7 +271,7 @@
17 #if defined (__MINGW32__)
18 /* Use getch/_kbhit to check for available console input, in the same way
19 that we read it normally. */
20 - chars_avail = isatty (tty) ? _kbhit () : 0;
21 + chars_avail = isatty (tty) ? _win32_kbhit () : 0;
22 result = 0;
23 #endif
24
25 @@ -501,6 +506,120 @@
26 return (c);
27 }
28
29 +#if defined (__MINGW32__)
30 +#define _WIN32_READ_NOCHAR (-2)
31 +static char _win32_buf[16] = {'0'};
32 +static int _win32_bufidx = 0;
33 +
34 +static int
35 +_win32_getch_internal (int block)
36 +{
37 + INPUT_RECORD rec;
38 + DWORD evRead, waitResult;
39 + HANDLE hInput = (HANDLE) _get_osfhandle (fileno (rl_instream));
40 +
41 + if (_win32_bufidx > 0)
42 + return _win32_buf[--_win32_bufidx];
43 +
44 + hInput = (HANDLE) _get_osfhandle (fileno (rl_instream));
45 +
46 + do
47 + {
48 + if (! block)
49 + {
50 + if (WaitForSingleObject(hInput, _keyboard_input_timeout/1000) != WAIT_OBJECT_0)
51 + return _WIN32_READ_NOCHAR;
52 + }
53 +
54 + if (!ReadConsoleInput(hInput, &rec, 1, &evRead) || evRead != 1)
55 + return EOF;
56 +
57 + switch (rec.EventType)
58 + {
59 + case KEY_EVENT:
60 + if ((rec.Event.KeyEvent.bKeyDown &&
61 + (rec.Event.KeyEvent.wVirtualKeyCode < VK_SHIFT ||
62 + rec.Event.KeyEvent.wVirtualKeyCode > VK_MENU)) ||
63 + (!rec.Event.KeyEvent.bKeyDown &&
64 + rec.Event.KeyEvent.wVirtualKeyCode == VK_MENU &&
65 + rec.Event.KeyEvent.uChar.AsciiChar))
66 + {
67 + if (rec.Event.KeyEvent.uChar.AsciiChar)
68 + {
69 + if (rec.Event.KeyEvent.uChar.AsciiChar < 0 ||
70 + (rec.Event.KeyEvent.uChar.AsciiChar < 32 &&
71 + !(rec.Event.KeyEvent.dwControlKeyState & (RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED))))
72 + {
73 + char c = rec.Event.KeyEvent.uChar.AsciiChar;
74 + if (GetOEMCP () == GetConsoleCP ())
75 + OemToCharBuff (&c, &c, 1);
76 + return (int)(unsigned char)c;
77 + }
78 + else
79 + return (int)rec.Event.KeyEvent.uChar.UnicodeChar;
80 + }
81 + else
82 + switch (rec.Event.KeyEvent.wVirtualKeyCode)
83 + {
84 + case VK_UP:
85 + _win32_buf[_win32_bufidx++] = 'H';
86 + return 0340;
87 + case VK_DOWN:
88 + _win32_buf[_win32_bufidx++] = 'P';
89 + return 0340;
90 + case VK_RIGHT:
91 + _win32_buf[_win32_bufidx++] = 'M';
92 + return 0340;
93 + case VK_LEFT:
94 + _win32_buf[_win32_bufidx++] = 'K';
95 + return 0340;
96 + case VK_HOME:
97 + _win32_buf[_win32_bufidx++] = 'G';
98 + return 0340;
99 + case VK_END:
100 + _win32_buf[_win32_bufidx++] = 'O';
101 + return 0340;
102 + case VK_DELETE:
103 + _win32_buf[_win32_bufidx++] = 'S';
104 + return 0340;
105 + default:
106 + break;
107 + }
108 + }
109 + break;
110 +
111 + case WINDOW_BUFFER_SIZE_EVENT:
112 + rl_resize_terminal ();
113 + break;
114 +
115 + default:
116 + break;
117 + }
118 + }
119 + while (1);
120 +}
121 +
122 +static int
123 +_win32_kbhit (void)
124 +{
125 + int result;
126 +
127 + result = _win32_getch_internal (0);
128 + if (result == _WIN32_READ_NOCHAR
129 + || result == EOF)
130 + return 0;
131 + _win32_buf[_win32_bufidx++] = result;
132 +
133 + return _win32_bufidx;
134 +}
135 +
136 +static int
137 +_win32_getch (void)
138 +{
139 + return _win32_getch_internal (1);
140 +}
141 +#endif
142 +
143 int
144 rl_getc (FILE *stream)
145 {
146 @@ -520,9 +639,9 @@
147 #if defined (__MINGW32__)
148 if (isatty (fileno (stream)))
149 {
150 - int c = _getch ();
151 + int c = _win32_getch ();
152 if (c == 0xe0)
153 - rl_execute_next (_getch ());
154 + rl_execute_next (_win32_getch ());
155 return (c);
156 }
157 #endif