未验证 提交 da389bf8 编写于 作者: 羽飞's avatar 羽飞 提交者: GitHub

客户端命令行增强 (#120)

如果使用readline,可以记录历史命令
上级 5b7a5208
...@@ -31,6 +31,7 @@ See the Mulan PSL v2 for more details. */ ...@@ -31,6 +31,7 @@ See the Mulan PSL v2 for more details. */
#ifdef USE_READLINE #ifdef USE_READLINE
#include "readline/readline.h" #include "readline/readline.h"
#include "readline/history.h"
#endif #endif
#define MAX_MEM_BUFFER_SIZE 8192 #define MAX_MEM_BUFFER_SIZE 8192
...@@ -39,9 +40,26 @@ See the Mulan PSL v2 for more details. */ ...@@ -39,9 +40,26 @@ See the Mulan PSL v2 for more details. */
using namespace common; using namespace common;
#ifdef USE_READLINE #ifdef USE_READLINE
const std::string HISTORY_FILE = std::string(getenv("HOME")) + "/.miniob.history";
char *my_readline(const char *prompt) char *my_readline(const char *prompt)
{ {
return readline(prompt); int size = history_length;
if (size == 0) {
read_history(HISTORY_FILE.c_str());
FILE *fp = fopen(HISTORY_FILE.c_str(), "a");
if (fp != nullptr) {
fclose(fp);
}
}
char *line = readline(prompt);
if (line != nullptr && line[0] != 0) {
add_history(line);
append_history(1, HISTORY_FILE.c_str());
}
return line;
} }
#else // USE_READLINE #else // USE_READLINE
char *my_readline(const char *prompt) char *my_readline(const char *prompt)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册