1 file changed, +9, -5
89bbf6drefactor(render/pixels.py): add _mark nested function to cleanup overuse of ternary op
author
mogi <git@mogiya.dev> on 31-05-2026 19:46 UTC+1
committer
mogi <git@mogiya.dev> on 31-05-2026 19:46 UTC+1
parent6fb99a1
      @@ -108,17 +108,21 @@ def render_maze(
108108         Glyph set depends on pure_ascii: solid blocks for Unicode mode,
109109         ascii markers (##, E, X, .., ~~) otherwise. Always colored.
110110         """
   111+        def _mark(color: str, ascii_glyph: str) -> str:
   112+            """Wrap a glyph in color; use PIXEL block unless pure_ascii."""
   113+            return color + (ascii_glyph if pure_ascii else PIXEL) + rs
   114+
111115         px, py = 2 * pos[0] + 1, 2 * pos[1] + 1
112116         if pos in pattern:
113   -            return dc + ("##" if pure_ascii else PIXEL) + rs
   117+            return _mark(dc, "##")
114118         if pos == gen.entry:
115   -            return ec + ("E " if pure_ascii else PIXEL) + rs
   119+            return _mark(ec, "E ")
116120         if pos == gen.exit_:
117   -            return xc + ("X " if pure_ascii else PIXEL) + rs
   121+            return _mark(xc, "X ")
118122         if (px, py) in path_px:
119   -            return pc + (".." if pure_ascii else PIXEL) + rs
   123+            return _mark(pc, "..")
120124         if visited_cells is not None and pos in visited_cells:
121   -            return vc + ("~~" if pure_ascii else PIXEL) + rs
   125+            return _mark(vc, "~~")
122126         return "  " if pure_ascii else PIXEL
123127 
124128     def _color_pixel(px: int, py: int) -> str: