tos library / Examples
Examples
Self-contained recipes that combine multiple parts of the API.
Persistent notes app
# tosapps/notes.py
import os, tos
data = tos.appdata.path("notes")
notes_file = os.path.join(data, "notes.txt")
tos.term.cls()
print("--- notes ---")
if os.path.exists(notes_file):
with open(notes_file) as f:
print(f.read())
new = input("> ")
with open(notes_file, "a") as f:
f.write(new + "\n")
Root-gated uninstaller
# tosapps/wipeapp.py
import shutil, tos
if not tos.is_root():
print("This action requires root mode.")
raise SystemExit(1)
target = input("App to wipe: ")
shutil.rmtree(tos.appdata.path(target))
print("Done.")
Banner with version footer
import tos
tos.term.cls()
print("==========================")
print(" My Cool TrashOS App")
print("==========================")
print(f"powered by tos {tos.version}")
See the API reference for the full description of each helper.