From 0834920d970dc54504b9053ef66b2d018ab288ee Mon Sep 17 00:00:00 2001 From: Denis Shilin Date: Tue, 27 May 2025 18:20:32 +0300 Subject: [PATCH] Preserve history, simplify banner --- README.md | 1 + hyaml/__init__.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 222f401..2ed5a47 100644 --- a/README.md +++ b/README.md @@ -242,6 +242,7 @@ $ hyaml True >>> ``` +Your command history is stored in the `~/.hyaml_history` file. ## ANTLR diff --git a/hyaml/__init__.py b/hyaml/__init__.py index 86e1abe..f0dca10 100644 --- a/hyaml/__init__.py +++ b/hyaml/__init__.py @@ -1,4 +1,6 @@ def main(): + import os + import readline from hyaml.translator import translate from hyaml.compiler import compile_expression from code import interact @@ -7,4 +9,12 @@ def evaluate(expr, **lcls): fn = compile_expression(expr, bindings=("variables",)) return fn(variables=lcls) - interact(local={"evaluate": evaluate, "translate": translate}) + histfile = os.path.join(os.path.expanduser("~"), ".hyaml_history") + try: + readline.read_history_file(histfile) + except FileNotFoundError: + pass + + interact(banner="HYAML Playgroud", local={"evaluate": evaluate, "translate": translate}) + + readline.write_history_file(histfile)