Skip to content

Commit

Permalink
aliasing
Browse files Browse the repository at this point in the history
  • Loading branch information
ms-jpq committed Apr 26, 2024
1 parent fbc3538 commit dac7ee3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
6 changes: 6 additions & 0 deletions assets/aliases.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
icon_colours: {}
text_colours:
ext_exact: {}
name_exact: {}
name_glob: {}
6 changes: 0 additions & 6 deletions assets/colour_aliases.yml

This file was deleted.

10 changes: 7 additions & 3 deletions chadtree/view/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def _suffixx(path: PurePath) -> _Str:
return _EMPTY


def _lax_suffix(path: PurePath) -> str:
return path.suffix or path.name


@lru_cache(maxsize=None)
def _gen_comp(sortby: Sequence[Sortby]) -> Callable[[Node], Any]:
def comp(node: Node) -> Sequence[Any]:
Expand Down Expand Up @@ -105,7 +109,7 @@ def search_icon_hl(node: Node, ignored: bool) -> Optional[str]:
if ignored:
return context.particular_mappings.ignored
else:
return context.icon_exts.get(node.path.suffix)
return context.icon_exts.get(_lax_suffix(node.path))

def search_text_hl(node: Node, ignored: bool) -> Optional[str]:
if ignored:
Expand All @@ -125,7 +129,7 @@ def search_text_hl(node: Node, ignored: bool) -> Optional[str]:
if fnmatch(node.path.name, pattern):
return hl

if hl := context.ext_exact.get(node.path.suffix):
if hl := context.ext_exact.get(_lax_suffix(node.path)):
return hl

for mode in s_modes:
Expand Down Expand Up @@ -158,7 +162,7 @@ def gen_icon(node: Node) -> Iterator[str]:
yield (
(
icons.name_exact.get(node.path.name, "")
or icons.ext_exact.get(node.path.suffix, "")
or icons.ext_exact.get(_lax_suffix(node.path), "")
or next(
(
v
Expand Down
24 changes: 22 additions & 2 deletions ci/text_decorations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from dataclasses import dataclass
from json import loads
from pathlib import Path
from typing import Mapping, Tuple
Expand All @@ -11,8 +12,23 @@

from ..run import docker_run


@dataclass(frozen=True)
class _TCAliases:
ext_exact: Mapping[str, str]
name_exact: Mapping[str, str]
name_glob: Mapping[str, str]


@dataclass(frozen=True)
class _Aliases:
icon_colours: Mapping[str, str]
text_colours: _TCAliases


_DOCKERFILE = Path(__file__).resolve(strict=True).with_name("Dockerfile")
_ICON_BASE = ASSETS / "icon_base.yml"
_ALIASES = ASSETS / "aliases.yml"


def _process_exts(exts: Mapping[str, str]) -> Mapping[str, str]:
Expand Down Expand Up @@ -62,11 +78,15 @@ def _make_lightmode(colours: TextColours) -> TextColours:
def load_text_decors() -> Tuple[IconGlyphSet, TextColourSet]:
i_decode = new_decoder[IconGlyphSet](IconGlyphSet, strict=False)
c_decode = new_decoder[TextColourSet](TextColourSet, strict=False)
a_decode = new_decoder[_Aliases](_Aliases)

icon_base = safe_load(_ICON_BASE.read_text("UTF-8"))
aliases = safe_load(_ALIASES.read_text("UTF-8"))

yaml = safe_load(_ICON_BASE.read_text("UTF-8"))
json = loads(docker_run(_DOCKERFILE))
data = merge(json, yaml)
data = merge(json, icon_base)
icon_spec = i_decode(data)
ali = a_decode(aliases)

icon_set = IconGlyphSet(
ascii=_process_icons(icon_spec.ascii),
Expand Down

0 comments on commit dac7ee3

Please sign in to comment.