diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2012-12-27 23:15:31 -0800 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2012-12-27 23:15:31 -0800 |
| commit | be122b73d35f20f44b5d220cd94a09918a33f121 (patch) | |
| tree | 176339be0e016da0f98ffbc853fcd26cb4d205f5 | |
| parent | 5ae22ea4b3c778607cbd55f43037e63264adcebe (diff) | |
| parent | 1d91470db676b2b5f269779dac0fcc8f1b24a711 (diff) | |
| download | mruby-be122b73d35f20f44b5d220cd94a09918a33f121.tar.gz mruby-be122b73d35f20f44b5d220cd94a09918a33f121.zip | |
Merge pull request #674 from mattn/readline
use readline if it's enabled.
| -rw-r--r-- | tools/mirb/mirb.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/tools/mirb/mirb.c b/tools/mirb/mirb.c index d3903ef57..b89c63cff 100644 --- a/tools/mirb/mirb.c +++ b/tools/mirb/mirb.c @@ -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) { |
