mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 16:34:47 +01:00
JSON done.
This commit is contained in:
parent
3f6d5ee793
commit
9a212b834d
3 changed files with 14 additions and 15 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue