Page MenuHomePhorge

theme.py
No OneTemporary

Size
829 B
Referenced Files
None
Subscribers
None

theme.py

import sys
try:
import tomllib
except ModuleNotFoundError:
try:
import tomli as tomllib
except ModuleNotFoundError as exc:
raise ModuleNotFoundError(
"No TOML parser available. Use Python 3.11+ or install 'tomli'."
) from exc
with open(sys.argv[1], "rb") as f:
theme = tomllib.load(f)
colors = theme.get("colors", {})
def to_enum(name):
return "HL_" + name.upper()
print("#ifndef THEME_H")
print("#define THEME_H")
print("")
print('#include "highlight.h"')
print("")
print("static const char *hl_theme_color(hl_token_class cls) {")
print(" switch (cls) {")
for name, value in colors.items():
escaped = value.replace("\\", "\\\\").replace('"', '\\"')
print(f' case {to_enum(name)}: return "{escaped}";')
print(" default: return NULL;")
print(" }")
print("}")
print("")
print("#endif")

File Metadata

Mime Type
text/x-script.python
Expires
Sat, Apr 4, 8:07 AM (1 d, 22 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
520868
Default Alt Text
theme.py (829 B)

Event Timeline