mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Save mirb history when readline enabled
This commit is contained in:
@@ -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)
|
||||
{
|
||||
@@ -268,6 +276,16 @@ main(int argc, char **argv)
|
||||
if (args.verbose) cxt->dump_result = 1;
|
||||
|
||||
ai = mrb_gc_arena_save(mrb);
|
||||
|
||||
#ifdef ENABLE_READLINE
|
||||
using_history();
|
||||
strcpy(history_path, getenv("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 +379,9 @@ main(int argc, char **argv)
|
||||
mrbc_context_free(mrb, cxt);
|
||||
mrb_close(mrb);
|
||||
|
||||
#ifdef ENABLE_READLINE
|
||||
write_history(history_path);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user