Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
0d4bd01c
Commit
0d4bd01c
authored
Mar 05, 2014
by
takkaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support linenoise in mirb
parent
e5e5aadf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
8 deletions
+22
-8
mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
+22
-8
No files found.
mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
View file @
0d4bd01c
...
...
@@ -15,15 +15,29 @@
#include "mruby/string.h"
#ifdef ENABLE_READLINE
#include <limits.h>
#include <readline/readline.h>
#include <readline/history.h>
#define MIRB_ADD_HISTORY(line) add_history(line)
#define MIRB_READLINE(ch) readline(ch)
#define MIRB_WRITE_HISTORY(path) write_history(path)
#define MIRB_READ_HISTORY(path) read_history(path)
#define MIRB_USING_HISTORY() using_history()
#elif ENABLE_LINENOISE
#define ENABLE_READLINE
#include <linenoise.h>
#define MIRB_ADD_HISTORY(line) linenoiseHistoryAdd(line)
#define MIRB_READLINE(ch) linenoise(ch)
#define MIRB_WRITE_HISTORY(path) linenoiseHistorySave(path)
#define MIRB_READ_HISTORY(path) linenoiseHistoryLoad(history_path)
#define MIRB_USING_HISTORY()
#endif
#ifdef ENABLE_READLINE
#include <limits.h>
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
)
{
...
...
@@ -281,7 +295,7 @@ main(int argc, char **argv)
ai
=
mrb_gc_arena_save
(
mrb
);
#ifdef ENABLE_READLINE
using_history
();
MIRB_USING_HISTORY
();
home
=
getenv
(
"HOME"
);
#ifdef _WIN32
if
(
!
home
)
...
...
@@ -291,7 +305,7 @@ main(int argc, char **argv)
strcpy
(
history_path
,
home
);
strcat
(
history_path
,
"/"
);
strcat
(
history_path
,
history_file_name
);
read_history
(
history_path
);
MIRB_READ_HISTORY
(
history_path
);
}
#endif
...
...
@@ -312,13 +326,13 @@ main(int argc, char **argv)
last_code_line
[
char_index
]
=
'\0'
;
#else
char
*
line
=
readline
(
code_block_open
?
"* "
:
"> "
);
char
*
line
=
MIRB_READLINE
(
code_block_open
?
"* "
:
"> "
);
if
(
line
==
NULL
)
{
printf
(
"
\n
"
);
break
;
}
strncpy
(
last_code_line
,
line
,
sizeof
(
last_code_line
)
-
1
);
add_history
(
line
);
MIRB_ADD_HISTORY
(
line
);
free
(
line
);
#endif
...
...
@@ -387,7 +401,7 @@ main(int argc, char **argv)
mrb_close
(
mrb
);
#ifdef ENABLE_READLINE
write_history
(
history_path
);
MIRB_WRITE_HISTORY
(
history_path
);
#endif
return
0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment