From 9a212b834d01f71b554803b5e59f53ee08029b90 Mon Sep 17 00:00:00 2001 From: Eadaen1 Date: Tue, 15 Sep 2020 15:49:42 +0100 Subject: [PATCH] JSON done. --- xonsh/history/base.py | 7 ++++++- xonsh/history/json.py | 18 +++++++----------- xonsh/history/main.py | 4 +--- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/xonsh/history/base.py b/xonsh/history/base.py index f4c31eec3..f0ae9f35f 100644 --- a/xonsh/history/base.py +++ b/xonsh/history/base.py @@ -170,4 +170,9 @@ class History: def clear(self): """Wipes the current session from both the disk and memory.""" - pass + self.buffer = None + self.inps = None + self.rtns = None + self.tss = None + self.outs = None + diff --git a/xonsh/history/json.py b/xonsh/history/json.py index 01cced8cc..1c13c77c2 100644 --- a/xonsh/history/json.py +++ b/xonsh/history/json.py @@ -269,9 +269,6 @@ class JsonHistoryFlusher(threading.Thread): load_hist_len = len(hist["cmds"]) hist["cmds"].extend(cmds) if self.at_exit: - #print(hist["ts"]) - print(hist.__class__) - print(hist) hist["ts"][1] = time.time() # apply end time hist["locked"] = False if not builtins.__xonsh__.env.get("XONSH_STORE_STDOUT", False): @@ -512,16 +509,15 @@ class JsonHistory(History): time.sleep(0.1) # don't monopolize the thread (or Python GIL?) def clear(self): - def wipe_disk(hist): - with open(self.filename, "r") as f: - backup_metadata = json.load(f) - backup_metadata["data"]["cmds"] = [] - print(backup_metadata) - with open(self.filename, "w") as f: - json.dump(backup_metadata, f) def wipe_memory(hist): # todo is this enough? hist.buffer = [] + self.tss = JsonCommandField("ts", self) + self.inps = JsonCommandField("inp", self) + self.outs = JsonCommandField("out", self) + self.rtns = JsonCommandField("rtn", self) - wipe_disk(self) wipe_memory(self) + + # Flush empty history object to disk. This overwrites the old commands. + self.flush() diff --git a/xonsh/history/main.py b/xonsh/history/main.py index f99e10291..dc717710a 100644 --- a/xonsh/history/main.py +++ b/xonsh/history/main.py @@ -430,14 +430,12 @@ def history_main( hf.join() elif ns.action == "off": if hist.remember_history: - hist.remember_history = False hist.clear() + hist.remember_history = False elif ns.action == "on": if not hist.remember_history: hist.remember_history = True - hist.remake_file() elif ns.action == "clear": hist.clear() - hist.remake_file() else: print("Unknown history action {}".format(ns.action), file=sys.stderr)