Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F3085304
theme.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
829 B
Referenced Files
None
Subscribers
None
theme.py
View Options
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
Details
Attached
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)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment