import json
import os
import sys
import threading
def notes_path() -> str:
config = os.environ.get("XDG_CONFIG_HOME", os.path.expanduser("~/.config"))
return os.path.join(config, "par-term", "notes.md")
def read_notes() -> str:
try:
with open(notes_path(), "r", encoding="utf-8") as f:
return f.read().strip()
except OSError:
return ""
def main() -> None:
wake = threading.Event()
def watch_stdin() -> None:
while sys.stdin.readline() != "":
wake.set()
wake.set()
threading.Thread(target=watch_stdin, daemon=True).start()
while True:
notes = read_notes()
if notes:
cmd = {
"type": "SetPanel",
"title": "Session notes",
"content": notes,
}
else:
cmd = {"type": "ClearPanel"}
print(json.dumps(cmd), flush=True)
wake.wait(60.0)
wake.clear()
if __name__ == "__main__":
main()