mirror of
https://github.com/caelestia-dots/cli.git
synced 2026-06-05 23:09:27 -05:00
theme: inject mode into user templates (#77)
* theme: apply_user_templates accepts mode.
* Some themes like those in NvChad require a mode to be supplied to
work. Added a minimal change that makes apply_user_templates accept a
mode parameter and replaces any {{ mode }} placeholder in a file with
the actual mode.
* theme: mode replace integrated with gen_replace_dynamic
+ Moved the {{ mode }} replacement logic to the gen_replace_dynamic
function.
* refactor: adjusted comment
This commit is contained in:
@@ -39,7 +39,7 @@ def gen_replace(colours: dict[str, str], template: Path, hash: bool = False) ->
|
|||||||
return template
|
return template
|
||||||
|
|
||||||
|
|
||||||
def gen_replace_dynamic(colours: dict[str, str], template: Path) -> str:
|
def gen_replace_dynamic(colours: dict[str, str], template: Path, mode: str) -> str:
|
||||||
def fill_colour(match: re.Match) -> str:
|
def fill_colour(match: re.Match) -> str:
|
||||||
data = match.group(1).strip().split(".")
|
data = match.group(1).strip().split(".")
|
||||||
if len(data) != 2:
|
if len(data) != 2:
|
||||||
@@ -50,10 +50,16 @@ def gen_replace_dynamic(colours: dict[str, str], template: Path) -> str:
|
|||||||
return getattr(colours_dyn[col], form)
|
return getattr(colours_dyn[col], form)
|
||||||
|
|
||||||
# match atomic {{ . }} pairs
|
# match atomic {{ . }} pairs
|
||||||
field = r"\{\{((?:(?!\{\{|\}\}).)*)\}\}"
|
dotField = r"\{\{((?:(?!\{\{|\}\}).)*)\}\}"
|
||||||
|
|
||||||
|
# match {{ mode }}
|
||||||
|
modeField = r"\{\{\s*mode\s*\}\}"
|
||||||
|
|
||||||
colours_dyn = get_dynamic_colours(colours)
|
colours_dyn = get_dynamic_colours(colours)
|
||||||
template_content = template.read_text()
|
template_content = template.read_text()
|
||||||
template_filled = re.sub(field, fill_colour, template_content)
|
|
||||||
|
template_filled = re.sub(dotField, fill_colour, template_content)
|
||||||
|
template_filled = re.sub(modeField, mode, template_content)
|
||||||
|
|
||||||
return template_filled
|
return template_filled
|
||||||
|
|
||||||
@@ -229,13 +235,13 @@ def apply_cava(colours: dict[str, str]) -> None:
|
|||||||
|
|
||||||
|
|
||||||
@log_exception
|
@log_exception
|
||||||
def apply_user_templates(colours: dict[str, str]) -> None:
|
def apply_user_templates(colours: dict[str, str], mode: str) -> None:
|
||||||
if not user_templates_dir.is_dir():
|
if not user_templates_dir.is_dir():
|
||||||
return
|
return
|
||||||
|
|
||||||
for file in user_templates_dir.iterdir():
|
for file in user_templates_dir.iterdir():
|
||||||
if file.is_file():
|
if file.is_file():
|
||||||
content = gen_replace_dynamic(colours, file)
|
content = gen_replace_dynamic(colours, file, mode)
|
||||||
write_file(theme_dir / file.name, content)
|
write_file(theme_dir / file.name, content)
|
||||||
|
|
||||||
|
|
||||||
@@ -272,4 +278,4 @@ def apply_colours(colours: dict[str, str], mode: str) -> None:
|
|||||||
apply_warp(colours, mode)
|
apply_warp(colours, mode)
|
||||||
if check("enableCava"):
|
if check("enableCava"):
|
||||||
apply_cava(colours)
|
apply_cava(colours)
|
||||||
apply_user_templates(colours)
|
apply_user_templates(colours, mode)
|
||||||
|
|||||||
Reference in New Issue
Block a user