Commit be122b73 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #674 from mattn/readline

use readline if it's enabled.
parents 5ae22ea4 1d91470d
......@@ -12,6 +12,10 @@
#include <mruby/proc.h>
#include <mruby/data.h>
#include <mruby/compile.h>
#ifdef ENABLE_READLINE
#include <readline/readline.h>
#include <readline/history.h>
#endif
#ifndef ENABLE_STDIO
#include <mruby/string.h>
......@@ -143,10 +147,12 @@ print_cmdline(int code_block_open)
int
main(void)
{
int last_char;
char ruby_code[1024] = { 0 };
char last_code_line[1024] = { 0 };
#ifndef ENABLE_READLINE
int last_char;
int char_index;
#endif
mrbc_context *cxt;
struct mrb_parser_state *parser;
mrb_state *mrb;
......@@ -167,6 +173,7 @@ main(void)
cxt->capture_errors = 1;
while (TRUE) {
#ifndef ENABLE_READLINE
print_cmdline(code_block_open);
char_index = 0;
......@@ -180,6 +187,12 @@ main(void)
}
last_code_line[char_index] = '\0';
#else
char* line = readline(code_block_open ? "* " : "> ");
strncat(last_code_line, line, sizeof(last_code_line)-1);
add_history(line);
free(line);
#endif
if ((strcmp(last_code_line, "quit") == 0) || (strcmp(last_code_line, "exit") == 0)) {
if (!code_block_open) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment