Skip to content

Commit 0e3102a

Browse files
authored
Merge pull request #79 from Oldes/io
Char based console input
2 parents bd91b59 + d229233 commit 0e3102a

File tree

9 files changed

+402
-99
lines changed

9 files changed

+402
-99
lines changed

src/boot/sysobj.reb

+11
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,9 @@ view: object [
507507
focus
508508
unfocus
509509
scroll
510+
511+
control ;; used to pass control key events to a console port
512+
control-up ;; only on Windows?
510513
]
511514
event-keys: [
512515
; Event types. Order dependent for C and REBOL.
@@ -533,6 +536,14 @@ view: object [
533536
f10
534537
f11
535538
f12
539+
paste-start ;; Bracketed paste turned on - https://cirw.in/blog/bracketed-paste
540+
paste-end ;; Bracketed paste turned off
541+
escape ;; Escape key
542+
shift
543+
control
544+
alt
545+
pause
546+
capital
536547
]
537548
]
538549

src/core/a-lib.c

+14
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,20 @@ RL_API void RL_Free_Handle_Context(REBHOB *hob)
11861186
}
11871187

11881188

1189+
RL_API REBCNT RL_Decode_UTF8_Char(const REBYTE *str, REBCNT *len)
1190+
/*
1191+
** Converts a single UTF8 code-point (to 32 bit).
1192+
**
1193+
** Returns:
1194+
** 32 bit character code
1195+
** Arguments:
1196+
** src - UTF8 encoded data
1197+
** len - number of source bytes consumed.
1198+
*/
1199+
{
1200+
return Decode_UTF8_Char(&str, len);
1201+
}
1202+
11891203

11901204

11911205
#include "reb-lib-lib.h"

src/core/t-event.c

+9-10
Original file line numberDiff line numberDiff line change
@@ -265,20 +265,19 @@
265265
goto is_none;
266266

267267
case SYM_KEY:
268-
if (VAL_EVENT_TYPE(value) != EVT_KEY && VAL_EVENT_TYPE(value) != EVT_KEY_UP)
269-
goto is_none;
270-
n = VAL_EVENT_DATA(value); // key-words in top 16, chars in lower 16
271-
if (n & 0xffff0000) {
268+
n = VAL_EVENT_DATA(value);
269+
if (VAL_EVENT_TYPE(value) == EVT_KEY || VAL_EVENT_TYPE(value) == EVT_KEY_UP) {
270+
SET_CHAR(val, n);
271+
break;
272+
}
273+
else if (VAL_EVENT_TYPE(value) == EVT_CONTROL || VAL_EVENT_TYPE(value) == EVT_CONTROL_UP) {
272274
arg = Get_System(SYS_VIEW, VIEW_EVENT_KEYS);
273-
n = (n >> 16) - 1;
274-
if (IS_BLOCK(arg) && n < (REBINT)VAL_TAIL(arg)) {
275-
*val = *VAL_BLK_SKIP(arg, n);
275+
if (IS_BLOCK(arg) && n <= (REBINT)VAL_TAIL(arg)) {
276+
*val = *VAL_BLK_SKIP(arg, n-1);
276277
break;
277278
}
278-
goto is_none;
279279
}
280-
SET_CHAR(val, n);
281-
break;
280+
goto is_none;
282281

283282
case SYM_FLAGS:
284283
if (VAL_EVENT_FLAGS(value) & (1<<EVF_DOUBLE | 1<<EVF_CONTROL | 1<<EVF_SHIFT)) {

src/mezz/prot-http.reb

+1-1
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ anonymize: func[
717717
any [
718718
thru LF [
719719
"Authorization:" some SP some uri
720-
| ["X-Token:" | "X-Auth-Token:"]
720+
| ["X-Token:" | "X-Auth-Token:" | "X-goog-api-key:"]
721721
] some SP 0 4 uri change to LF "****"
722722
| skip
723723
]

src/os/posix/dev-event.c

+24-26
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include <unistd.h>
4343
#include <sys/time.h>
4444
#include <errno.h>
45+
#include <poll.h>
4546

4647
#include "reb-host.h"
4748
#include "host-lib.h"
@@ -54,7 +55,7 @@ extern REBINT exit_loop;
5455
REBINT exit_loop = 0;
5556
#endif
5657

57-
58+
extern struct pollfd poller; // currently in dev-stdio.c
5859

5960
void Done_Device(int handle, int error);
6061

@@ -110,17 +111,14 @@ void Done_Device(int handle, int error);
110111
**
111112
***********************************************************************/
112113
{
113-
struct timeval tv;
114-
int result;
114+
poll(&poller, 1, req->length);
115115

116-
tv.tv_sec = 0;
117-
tv.tv_usec = req->length * (exit_loop == 0 ? 1000 : 200); // don't wait so much when gui is used
118-
//printf("usec %d\n", tv.tv_usec);
116+
// struct timeval tv;
119117

120-
#ifdef REB_VIEW
121-
int max_priority;
122-
GPollFD poll_fds[10];
123-
gint timeout = tv.tv_usec;
118+
//#ifdef REB_VIEW
119+
//int max_priority;
120+
//GPollFD poll_fds[10];
121+
//gint timeout = tv.tv_usec;
124122

125123
//if (g_main_context_acquire(GTKCtx)) {
126124
// if (g_main_context_prepare(GTKCtx, &max_priority)) {
@@ -130,22 +128,22 @@ void Done_Device(int handle, int error);
130128
// g_main_context_release(GTKCtx);
131129
// if (result >= 0) return DR_DONE;
132130
//}
133-
#endif
134-
135-
result = select(0, 0, 0, 0, &tv);
136-
if (result < 0) {
137-
//
138-
// !!! In R3-Alpha this had a TBD that said "set error code" and had a
139-
// printf that said "ERROR!!!!". However this can happen when a
140-
// Ctrl-C interrupts a timer on a WAIT. As a patch this is tolerant
141-
// of EINTR, but still returns the error code. :-/
142-
//
143-
if (errno == EINTR)
144-
return DR_ERROR;
145-
146-
printf("select() returned -1 in dev-event.c (I/O error!)\n");
147-
return DR_ERROR;
148-
}
131+
//#endif
132+
133+
// int result = select(STDIN_FILENO+1, &readfds, 0, 0, &tv);
134+
// if (result < 0) {
135+
// //
136+
// // !!! In R3-Alpha this had a TBD that said "set error code" and had a
137+
// // printf that said "ERROR!!!!". However this can happen when a
138+
// // Ctrl-C interrupts a timer on a WAIT. As a patch this is tolerant
139+
// // of EINTR, but still returns the error code. :-/
140+
// //
141+
// if (errno == EINTR)
142+
// return DR_ERROR;
143+
//
144+
// printf("select() returned -1 in dev-event.c (I/O error!)\n");
145+
// return DR_ERROR;
146+
// }
149147

150148
return DR_DONE;
151149
}

0 commit comments

Comments
 (0)