diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2013-07-18 19:31:54 -0700 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2013-07-18 19:31:54 -0700 |
| commit | 88731e1756653da09e0497d7e83dc522f4767136 (patch) | |
| tree | 860b8ba7f6cb36e9327ae235a6e4828d5036a8d9 | |
| parent | 70d7031e7a373ed5d22453c30c082906bbd42373 (diff) | |
| parent | 1fe65b2522fb480a5c70a2ac5925c223efd9c492 (diff) | |
| download | mruby-88731e1756653da09e0497d7e83dc522f4767136.tar.gz mruby-88731e1756653da09e0497d7e83dc522f4767136.zip | |
Merge pull request #1390 from kyab/mirb_history
Save mirb history when readline enabled
| -rw-r--r-- | mrbgems/mruby-bin-mirb/tools/mirb/mirb.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c b/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c index eb7194f30..3111eea8f 100644 --- a/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +++ b/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c @@ -15,11 +15,19 @@ #include <mruby/data.h> #include <mruby/compile.h> #ifdef ENABLE_READLINE +#include <limits.h> #include <readline/readline.h> #include <readline/history.h> #endif #include <mruby/string.h> + +#ifdef ENABLE_READLINE +static const char *history_file_name = ".mirb_history"; +char history_path[PATH_MAX]; +#endif + + static void p(mrb_state *mrb, mrb_value obj, int prompt) { @@ -245,6 +253,7 @@ main(int argc, char **argv) int n; int code_block_open = FALSE; int ai; + char *home = NULL; /* new interpreter instance */ mrb = mrb_open(); @@ -268,6 +277,21 @@ main(int argc, char **argv) if (args.verbose) cxt->dump_result = 1; ai = mrb_gc_arena_save(mrb); + +#ifdef ENABLE_READLINE + using_history(); + home = getenv("HOME"); +#ifdef _WIN32 + if (!home) + home = getenv("USERPROFILE"); +#endif + strcpy(history_path, home); + strcat(history_path, "/"); + strcat(history_path, history_file_name); + read_history(history_path); +#endif + + while (TRUE) { #ifndef ENABLE_READLINE print_cmdline(code_block_open); @@ -361,5 +385,9 @@ main(int argc, char **argv) mrbc_context_free(mrb, cxt); mrb_close(mrb); +#ifdef ENABLE_READLINE + write_history(history_path); +#endif + return 0; } |
