forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepl-basic.c
54 lines (46 loc) · 1.06 KB
/
repl-basic.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "repl.h"
char jl_prompt_color[] = "\033[1m\033[32mjulia> \033[0m\033[1m";
char *prompt_string = "julia> ";
void init_repl_environment(void)
{
}
DLLEXPORT void jl_enable_color(void)
{
prompt_string = jl_prompt_color;
}
void jl_input_line_callback(char *input)
{
jl_value_t *ast;
int end=0, doprint=1;
if (!input || ios_eof(ios_stdin)) {
end = 1;
ast = jl_nothing;
}
else {
ast = jl_parse_input_line(input);
// TODO
//if (jl_is_expr(ast) && ((jl_expr_t*)ast)->head == jl_continue_sym)
doprint = !ends_with_semicolon(input);
}
handle_input(ast, end, doprint);
}
char *read_expr(char *prompt)
{
char *input;
ios_printf(ios_stdout, prompt);
ios_flush(ios_stdout);
input = ios_readline(ios_stdin);
ios_purge(ios_stdin);
return input;
}
void repl_callback_enable()
{
ios_printf(ios_stdout, prompt_string);
ios_flush(ios_stdout);
}
void jl_stdin_callback(void)
{
char *input = ios_readline(ios_stdin);
ios_purge(ios_stdin);
jl_input_line_callback(input);
}