Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dark mode option #90

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions keymap_drawer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def draw(args: Namespace, config: DrawConfig) -> None:
keys_only=args.keys_only,
combos_only=args.combos_only,
ghost_keys=args.ghost_keys,
dark_mode=True if args.dark_mode == "yes" else False if args.dark_mode == "no" else None,
)


Expand Down Expand Up @@ -149,6 +150,14 @@ def main() -> None:
"see README for schema",
type=FileType("rt"),
)
draw_p.add_argument(
"--dark-mode",
help="Style the SVG for dark mode screens, will follow system settings if set to 'auto'",
choices=["yes", "no", "auto"],
default="no",
nargs="?",
const="yes",
)

parse_p = subparsers.add_parser(
"parse", help="parse a QMK/ZMK keymap to YAML representation to stdout, to be used with the `draw` command"
Expand Down
17 changes: 17 additions & 0 deletions keymap_drawer/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,23 @@ class KeySidePars(BaseModel):
),
)

# style CSS to overide colors for dark mode
svg_style_dark: str = Field(
exclude=True,
default=dedent(
"""\
svg.keymap { fill: #d1d6db }
rect.key { fill: #050709 }
rect.key, rect.combo { stroke: #303336 }
rect.combo, rect.combo-separate { fill: #001133 }
rect.held, rect.combo.held { fill: #220000 }
text.label { stroke: #000000 }
text.trans { fill: #7e8184 }
path.combo { stroke: #7f7f7f }
"""
),
)

# extra CSS to be appended to svg_style
# prefer to set this over modifying svg_style since the default value of svg_style can change
svg_extra_style: str = ""
Expand Down
9 changes: 8 additions & 1 deletion keymap_drawer/draw/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def print_board(
keys_only: bool = False,
combos_only: bool = False,
ghost_keys: Sequence[int] | None = None,
dark_mode: bool | None = None,
) -> None:
"""Print SVG code representing the keymap."""
layers = deepcopy(self.keymap.layers)
Expand Down Expand Up @@ -227,7 +228,13 @@ def print_board(
)
self.output_stream.write(self.get_glyph_defs())
extra_style = f"\n{self.cfg.svg_extra_style}" if self.cfg.svg_extra_style else ""
self.output_stream.write(f"<style>{self.cfg.svg_style}{extra_style}</style>\n")
if dark_mode is None and self.cfg.svg_style_dark:
dark_style = f"\n@media (prefers-color-scheme: dark) {{\n{self.cfg.svg_style_dark}\n}}"
elif dark_mode is True and self.cfg.svg_style_dark:
dark_style = f"\n{self.cfg.svg_style_dark}"
else:
dark_style = ""
self.output_stream.write(f"<style>{self.cfg.svg_style}{dark_style}{extra_style}</style>\n")
self.output_stream.write(self.out.getvalue())

if self.cfg.footer_text:
Expand Down
Loading