Skip to content

Commit

Permalink
removing no_readline variable and -R option
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed May 5, 2011
1 parent fd328f5 commit 655d321
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 91 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
/julia
/custom.j
/sys.ji
/libjulia-release.so
/libjulia-debug.so
4 changes: 2 additions & 2 deletions src/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*.do

/boot.j.inc
/julia-debug
/julia-release
/julia_flisp.boot
/julia_flisp.boot.inc
/libjulia-release.so
/libjulia-debug.so
9 changes: 9 additions & 0 deletions src/support/ios.c
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,15 @@ void ios_purge(ios_t *s)
}
}

char *ios_readline(ios_t *s)
{
ios_t dest;
ios_mem(&dest, 0);
ios_copyuntil(&dest, s, '\n');
size_t n;
return ios_takebuf(&dest, &n);
}

int vasprintf(char **strp, const char *fmt, va_list ap);

int ios_vprintf(ios_t *s, const char *format, va_list args)
Expand Down
7 changes: 4 additions & 3 deletions src/support/ios.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ int ios_getnum(ios_t *s, char *data, uint32_t type);
DLLEXPORT int ios_getutf8(ios_t *s, uint32_t *pwc);
int ios_peekutf8(ios_t *s, uint32_t *pwc);
int ios_ungetutf8(ios_t *s, uint32_t wc);
int ios_getstringz(ios_t *dest, ios_t *src);
int ios_getstringn(ios_t *dest, ios_t *src, size_t nchars);
int ios_getline(ios_t *s, char **pbuf, size_t *psz);
//int ios_getstringz(ios_t *dest, ios_t *src);
//int ios_getstringn(ios_t *dest, ios_t *src, size_t nchars);
//int ios_getline(ios_t *s, char **pbuf, size_t *psz);
char *ios_readline(ios_t *s);

// discard data buffered for reading
void ios_purge(ios_t *s);
Expand Down
3 changes: 3 additions & 0 deletions ui/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/*.o
/*.do
/julia-release-basic
/julia-release-cloud
/julia-release-readline
12 changes: 10 additions & 2 deletions ui/repl-basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ char jl_prompt_color[] = "\033[1m\033[32mjulia> \033[37m";

void init_repl_environment()
{
no_readline = 1;
}

void exit_repl_environment()
Expand All @@ -24,7 +23,6 @@ DLLEXPORT void jl_input_line_callback(char *input)
ast = jl_parse_input_line(input);
// TODO
//if (jl_is_expr(ast) && ((jl_expr_t*)ast)->head == continue_sym)
//return read_expr_ast_no_readline(prompt, end, doprint);
doprint = !ends_with_semicolon(input);
}
handle_input(ast, end, doprint);
Expand All @@ -42,6 +40,8 @@ void read_expr(char *prompt)

void repl_callback_enable()
{
ios_printf(ios_stdout, prompt_string);
ios_flush(ios_stdout);
}

void repl_callback_disable()
Expand All @@ -50,4 +50,12 @@ void repl_callback_disable()

void repl_stdin_callback()
{
char *input = ios_readline(ios_stdin);
ios_purge(ios_stdin);
jl_input_line_callback(input);
}

void repl_print_prompt()
{
ios_printf(ios_stdout, prompt_string);
}
10 changes: 4 additions & 6 deletions ui/repl-cloud.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,6 @@ void init_repl_environment() {
// Wait until enter is pressed, then exit
printf("Julia is listening for exciting science on port %s.\n", mg_get_option(ctx, "listening_ports"));

no_readline = 1;

return;
}

Expand All @@ -468,7 +466,6 @@ DLLEXPORT void jl_input_line_callback(char *input)
ast = jl_parse_input_line(input);
// TODO
//if (jl_is_expr(ast) && ((jl_expr_t*)ast)->head == continue_sym)
//return read_expr_ast_no_readline(prompt, end, doprint);
doprint = !ends_with_semicolon(input);
}
handle_input(ast, end, doprint);
Expand All @@ -486,15 +483,16 @@ void read_expr(char *prompt)

void repl_callback_enable()
{
return;
}

void repl_callback_disable()
{
return;
}

void repl_stdin_callback()
{
return;
}

void repl_print_prompt()
{
}
47 changes: 23 additions & 24 deletions ui/repl-readline.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,38 +257,33 @@ void read_expr(char *prompt)

void init_repl_environment()
{
no_readline = 0;

if (!no_readline) {
init_history();
rl_bind_key(' ', space_callback);
rl_bind_key('\t', tab_callback);
rl_bind_key('\r', return_callback);
rl_bind_key('\n', return_callback);
rl_bind_key('\v', line_kill_callback);
rl_bind_key('\b', backspace_callback);
rl_bind_key('\001', line_start_callback);
rl_bind_key('\005', line_end_callback);
rl_bind_key('\002', left_callback);
rl_bind_key('\006', right_callback);
rl_bind_keyseq("\e[A", up_callback);
rl_bind_keyseq("\e[B", down_callback);
rl_bind_keyseq("\e[D", left_callback);
rl_bind_keyseq("\e[C", right_callback);
rl_bind_keyseq("\\C-d", delete_callback);
}
init_history();
rl_bind_key(' ', space_callback);
rl_bind_key('\t', tab_callback);
rl_bind_key('\r', return_callback);
rl_bind_key('\n', return_callback);
rl_bind_key('\v', line_kill_callback);
rl_bind_key('\b', backspace_callback);
rl_bind_key('\001', line_start_callback);
rl_bind_key('\005', line_end_callback);
rl_bind_key('\002', left_callback);
rl_bind_key('\006', right_callback);
rl_bind_keyseq("\e[A", up_callback);
rl_bind_keyseq("\e[B", down_callback);
rl_bind_keyseq("\e[D", left_callback);
rl_bind_keyseq("\e[C", right_callback);
rl_bind_keyseq("\\C-d", delete_callback);
}

void exit_repl_environment()
{
if (!no_readline) {
rl_callback_handler_remove();
}
rl_callback_handler_remove();
}

void repl_callback_enable()
{
rl_callback_handler_install(prompt_string, jl_input_line_callback);
if (jl_have_event_loop)
rl_callback_handler_install(prompt_string, jl_input_line_callback);
}

void repl_callback_disable()
Expand All @@ -300,3 +295,7 @@ void repl_stdin_callback()
{
rl_callback_read_char();
}

void repl_print_prompt()
{
}
67 changes: 14 additions & 53 deletions ui/repl.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static char jl_color_normal[] = "\033[0m\033[37m";
static int print_banner = 1;
static char *post_boot = NULL;
static int lisp_prompt = 0;
static int have_event_loop = 0;
int jl_have_event_loop = 0;
static char *program = NULL;

int num_evals = 0;
Expand All @@ -55,7 +55,6 @@ jl_value_t *rl_ast = NULL;
int tab_width = 2;
int prompt_length = 0;
int have_color = 1;
int no_readline = 1;

#ifdef CLOUD_REPL
char *repl_result;
Expand All @@ -64,7 +63,6 @@ char *repl_result;
static const char *usage = "julia [options] [program] [args...]\n";
static const char *opts =
" -q --quiet Quiet startup without banner\n"
" -R --no-readline Disable readline functionality\n"
" -H --home=<dir> Load files relative to <dir>\n"
" -T --tab=<size> Set REPL tab width to <size>\n\n"

Expand All @@ -79,10 +77,9 @@ static const char *opts =
" -h --help Print this message\n";

void parse_opts(int *argcp, char ***argvp) {
static char* shortopts = "qRe:E:P:H:T:bL:hJ:";
static char* shortopts = "qe:E:P:H:T:bL:hJ:";
static struct option longopts[] = {
{ "quiet", no_argument, 0, 'q' },
{ "no-readline", no_argument, 0, 'R' },
{ "eval", required_argument, 0, 'e' },
{ "print", required_argument, 0, 'E' },
{ "post-boot", required_argument, 0, 'P' },
Expand All @@ -103,12 +100,8 @@ void parse_opts(int *argcp, char ***argvp) {
case 'q':
print_banner = 0;
break;
case 'R':
no_readline = 1;
break;
case 'e':
case 'E':
no_readline = 1;
num_evals++;
eval_exprs = (char**)realloc(eval_exprs, num_evals*sizeof(char*));
print_exprs = (int*)realloc(print_exprs, num_evals*sizeof(int));
Expand Down Expand Up @@ -206,7 +199,6 @@ void parse_opts(int *argcp, char ***argvp) {
*argcp -= optind;
if (!num_evals && *argcp > 0) {
if (strcmp((*argvp)[0], "-")) {
no_readline = 1;
program = (*argvp)[0];
}
++*argvp; --*argcp;
Expand Down Expand Up @@ -238,25 +230,10 @@ static int detect_color()
#endif
}

char *ios_readline(ios_t *s)
{
ios_t dest;
ios_mem(&dest, 0);
ios_copyuntil(&dest, s, '\n');
size_t n;
return ios_takebuf(&dest, &n);
}

// called when we detect an event on stdin
DLLEXPORT void jl_stdin_callback()
{
if (no_readline) {
char *input = ios_readline(ios_stdin);
ios_purge(ios_stdin);
jl_input_line_callback(input);
} else {
repl_stdin_callback();
}
repl_stdin_callback();
}

static int exec_program()
Expand Down Expand Up @@ -336,13 +313,11 @@ static void repl_show_value(jl_value_t *v)

DLLEXPORT void jl_eval_user_input(jl_value_t *ast, int show_value)
{
if (!no_readline) {
if (have_event_loop) {
// with multi.j loaded the readline callback can return
// before the command finishes running, so we have to
// disable rl to prevent the prompt from reappearing too soon.
repl_callback_disable();
}
if (jl_have_event_loop) {
// with multi.j loaded the command line input callback can return
// before the command finishes running, so we have to
// disable rl to prevent the prompt from reappearing too soon.
repl_callback_disable();
}
JL_GC_PUSH(&ast);
assert(ast != NULL);
Expand Down Expand Up @@ -381,15 +356,7 @@ DLLEXPORT void jl_eval_user_input(jl_value_t *ast, int show_value)
ios_printf(ios_stdout, "\n");
ios_flush(ios_stdout);
JL_GC_POP();
if (no_readline) {
ios_printf(ios_stdout, prompt_string);
ios_flush(ios_stdout);
}
else {
if (have_event_loop) {
repl_callback_enable();
}
}
repl_callback_enable();
}

// handle a command line input event
Expand All @@ -401,9 +368,7 @@ void handle_input(jl_value_t *ast, int end, int show_value)
}
if (ast == NULL) {
ios_printf(ios_stdout, "\n");
if (no_readline) {
ios_printf(ios_stdout, prompt_string);
}
repl_print_prompt();
ios_flush(ios_stdout);
return;
}
Expand Down Expand Up @@ -537,11 +502,9 @@ int main(int argc, char *argv[])
(jl_function_t*)
jl_get_global(jl_system_module, jl_symbol("start_client"));

if (no_readline) {
ios_printf(ios_stdout, prompt_string);
ios_flush(ios_stdout);
}
if (start_client == NULL) {
repl_print_prompt();
ios_flush(ios_stdout);
// client event loop not available; use fallback blocking version
int iserr = 0;
again:
Expand All @@ -567,10 +530,8 @@ int main(int argc, char *argv[])
}
}
else {
have_event_loop = 1;
if (!no_readline) {
repl_callback_enable();
}
jl_have_event_loop = 1;
repl_callback_enable();
jl_apply(start_client, NULL, 0);
}

Expand Down
3 changes: 2 additions & 1 deletion ui/repl.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "llt.h"
#include "julia.h"

extern int no_readline;
extern char jl_prompt_color[];
extern int prompt_length;
extern int have_color;
Expand All @@ -31,6 +30,7 @@ extern jl_value_t *rl_ast;
extern char *jl_answer_color;
extern char *prompt_string;
extern char *julia_home;
extern int jl_have_event_loop;

extern void init_repl_environment();
extern void exit_repl_environment();
Expand All @@ -42,6 +42,7 @@ extern char *ios_readline(ios_t *s);
extern void repl_callback_enable();
extern void repl_callback_disable();
extern void repl_stdin_callback();
extern void repl_print_prompt();


#ifdef CLOUD_REPL
Expand Down

0 comments on commit 655d321

Please sign in to comment.