From 1ba10260c05103e6b59e9b8948ff9ce01cdee46a Mon Sep 17 00:00:00 2001 From: Richard Date: Mon, 25 Dec 2023 08:05:18 +0100 Subject: [PATCH] up arrow --- Dockerfile | 3 ++- main.py | 1 + nullptr/commander.py | 8 +++++++- requirements.txt | 1 + 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4f04926..75c67d5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,5 +8,6 @@ RUN pip3 install -r requirements.txt ADD --chown=user . /app RUN chmod +x /app/main.py VOLUME /data +#ENTRYPOINT bash ENTRYPOINT [ "python3", "/app/main.py"] -CMD ["-s", "/data/store.npt"] +CMD ["-s", "/data/store.npt", "-x", "/data/cmd.hst"] diff --git a/main.py b/main.py index 0290b3a..98416e4 100644 --- a/main.py +++ b/main.py @@ -12,5 +12,6 @@ def main(args): if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('-s', '--store-file', default='data/store.npt') + parser.add_argument('-x', '--history-file', default='data/cmd.hst') args = parser.parse_args() main(args) diff --git a/nullptr/commander.py b/nullptr/commander.py index 34a8694..5cf67a3 100644 --- a/nullptr/commander.py +++ b/nullptr/commander.py @@ -8,12 +8,17 @@ from .util import * from time import sleep, time from threading import Thread from nullptr.central_command import CentralCommand +import readline +import os class CommandError(Exception): pass class Commander(CommandLine): - def __init__(self, store_file='data/store.npt'): + def __init__(self, store_file='data/store.npt', hist_file = 'data/cmd.hst'): + self.hist_file = hist_file + if os.path.isfile(hist_file): + readline.read_history_file(hist_file) self.store = Store(store_file) self.agent = self.select_agent() self.api = Api(self.store, self.agent) @@ -26,6 +31,7 @@ class Commander(CommandLine): def handle_eof(self): self.store.close() + readline.write_history_file(self.hist_file) print("Goodbye!") def prompt(self): diff --git a/requirements.txt b/requirements.txt index f229360..1bb406c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ requests +readline