From 0f01f6959c4880d8c85d195ed051f4114c8e9b14 Mon Sep 17 00:00:00 2001 From: Mistivia Date: Thu, 19 Jun 2025 22:35:45 +0800 Subject: add readline history --- src/main.c | 1 - src/parser.c | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) 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 #include +#include #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; } -- cgit v1.0