aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-06-19 22:35:45 +0800
committerMistivia <i@mistivia.com>2025-06-19 22:35:45 +0800
commit0f01f6959c4880d8c85d195ed051f4114c8e9b14 (patch)
treec81c413439f3ae21cffcbb39565dc62baf6101f0
parentb7faf6f020743afb1c06161bc1696f66e0b788e0 (diff)
add readline history
-rw-r--r--src/main.c1
-rw-r--r--src/parser.c5
2 files changed, 5 insertions, 1 deletions
diff --git a/src/main.c b/src/main.c
index 9c05ee5..4fdb5b0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -9,7 +9,6 @@ int main() {
Interp_init(&interp);
Parser_init(&parser);
parser.ctx = &interp;
-
Parser_set_readline(&parser);
SExpRef sexp, res;
ParseResult parse_result;
diff --git a/src/parser.c b/src/parser.c
index 9ed583d..46a94b5 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -5,6 +5,7 @@
#include <stdarg.h>
#include <readline/readline.h>
+#include <readline/history.h>
#include "sexp.h"
@@ -56,6 +57,7 @@ void Parser_set_file(Parser *parser, FILE *fp) {
}
void Parser_set_readline(Parser *parser) {
+ stifle_history(100);
parser->parse_type = kParseReadline;
parser->string = NULL;
parser->str_cursor = NULL;
@@ -78,6 +80,7 @@ int Parser_getchar(Parser *ctx) {
ctx->readline_eof = true;
return EOF;
}
+ if (s[0] != '\0') { add_history(s); }
ctx->string = s;
ctx->str_cursor = s;
}
@@ -87,6 +90,7 @@ int Parser_getchar(Parser *ctx) {
ctx->readline_eof = true;
return EOF;
}
+ if (s[0] != '\0') { add_history(s); }
free((void*)ctx->string);
ctx->string = s;
ctx->str_cursor = s;
@@ -117,6 +121,7 @@ int Parser_peek(Parser *ctx) {
ctx->readline_eof = true;
return EOF;
}
+ if (s[0] != '\0') { add_history(s); }
ctx->string = s;
ctx->str_cursor = s;
}