Skip to content

Commit

Permalink
connect readline with a pipe instead of /dev/null. doesn't work for #…
Browse files Browse the repository at this point in the history
…2064 and introduces many more problems
  • Loading branch information
vtjnash committed Feb 2, 2013
1 parent c49dc08 commit c40d3ed
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions ui/repl-readline.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ void jl_prep_terminal (int meta_flag)
rl_instream = stdin;
rl_prep_terminal(1);
rl_instream = rl_in;
rl_prep_terminal(1);
#ifdef __WIN32__
if (!repl_sigint_handler_installed) {
if (SetConsoleCtrlHandler((PHANDLER_ROUTINE)repl_sigint_handler,1))
Expand Down Expand Up @@ -703,6 +704,10 @@ void jl_deprep_terminal ()
rl_instream = rl_in;
}

#include "uv.h"
static uv_pipe_t uv_pipe_from_jl;
static uv_pipe_t uv_pipe_to_rl;

void init_repl_environment(int argc, char *argv[])
{
disable_history = 0;
Expand All @@ -722,7 +727,14 @@ void init_repl_environment(int argc, char *argv[])
rl_catch_signals = 0;
rl_prep_term_function=&jl_prep_terminal;
rl_deprep_term_function=&jl_deprep_terminal;
rl_instream=fopen("/dev/null","r");
#ifndef __WIN32__
uv_pipe_init(uv_default_loop(), &uv_pipe_from_jl, UV_PIPE_WRITEABLE);
uv_pipe_init(uv_default_loop(), &uv_pipe_to_rl, UV_PIPE_READABLE|UV_PIPE_SPAWN_SAFE);
uv_pipe_link(&uv_pipe_to_rl, &uv_pipe_from_jl);
rl_instream = fdopen(uv_pipe_to_rl.accepted_fd, "w");
#else
rl_instream = open("/dev/null","r");
#endif
prompt_length = strlen(prompt_plain);
init_history();
rl_startup_hook = (Function*)init_rl;
Expand All @@ -734,17 +746,40 @@ void repl_callback_enable()
rl_callback_handler_install(prompt_string, jl_input_line_callback);
}

#include "uv.h"

static void jl_freeBuffer(uv_write_t* req, int status) {
size_t nread = 1;
if (req->data) {
size_t* data = (size_t*)req->data;
nread = data[-1];
free(data-1);
}
free(req);
size_t i;
for (i = 0; i < nread; i++) {
if (!callback_en)
break;
rl_callback_read_char();
}
}
void jl_readBuffer(char *base, ssize_t nread)
{
#ifdef __WIN32__
char *start = base;
while(*start != 0 && nread > 0) {
rl_stuff_char(*start);
start++;
nread--;
}
rl_callback_read_char();
#else
uv_write_t *uvw = malloc(sizeof(uv_write_t));
char *data = malloc(nread+sizeof(size_t))+sizeof(size_t);
memcpy(data, base, nread);
uv_buf_t buf[] = {{.base = data, .len = nread}};
uvw->data = data;
int err = uv_write(uvw, (uv_stream_t*)&uv_pipe_from_jl, buf, 1, &jl_freeBuffer);
(void)err;
#endif
}

void restart(void)
Expand Down

0 comments on commit c40d3ed

Please sign in to comment.