Dark mode v1 APPLIED

Frederick Yin: 1
 Dark mode

 3 files changed, 9 insertions(+), 6 deletions(-)
 > What will the format be? YAML, TOML, INI?

I like TOML the most so most likely that.

The idea is to have a mechanism where you define an option once and it 
becomes available as both a CLI arg and a config item, for example 
defining an `h1-font` option should make the application first read from 
`--h1-font` CLI arg, then fall back to `ht-font` key in the TOML stored 
in, say, `$XDG_CONFIG_HOME/mcross/mcross.toml`.
It's not worth implementing 2 different sets of configuration options IMO.
 > still be able to remain "simple but no simpler", if every node is
 > customizable

Well my stance is that only constant values should be configurable, not 
custom behavior. As long as we stick to that the config module should 
add no extra complexity to the rest of the code base. For example,
`bg = 'black' if config.dark else 'white'` is custom logic, while
`bg = config.bg` is just a configurable constant. I'm aiming for the 
latter, so while the number of configurable values increases, the 
complexity is actually decreased.
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~nhanb/mcross-devel/patches/11184/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] Dark mode Export this patch

This commit introduces CLI arg `--dark`, which toggles dark mode. The
effect should be like https://fkfd.me/static/mcross_dark.png
 src/mcross/__init__.py       |  1 +
 src/mcross/gui/controller.py |  4 +++-
 src/mcross/gui/view.py       | 10 +++++-----
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/mcross/__init__.py b/src/mcross/__init__.py
index 200999f..eb8be0e 100644
--- a/src/mcross/__init__.py
+++ b/src/mcross/__init__.py
@@ -9,6 +9,7 @@ def run():
    argparser = argparse.ArgumentParser()
    argparser.add_argument("--dark", action="store_true")
    args = argparser.parse_args()

    # Actually start the program
diff --git a/src/mcross/gui/controller.py b/src/mcross/gui/controller.py
index 92d59c7..ca6b684 100644
--- a/src/mcross/gui/controller.py
+++ b/src/mcross/gui/controller.py
@@ -25,7 +25,9 @@ class Controller:
        self.root = Tk()
        self.root.alt_shortcuts = set()
        self.model = Model()
        self.view = View(self.root, self.model, fonts=(args.textfont, args.monofont))
        self.view = View(
            self.root, self.model, fonts=(args.textfont, args.monofont), dark=args.dark
        self.root.title("McRoss Browser")

diff --git a/src/mcross/gui/view.py b/src/mcross/gui/view.py
index a52f30c..7e5ed33 100644
--- a/src/mcross/gui/view.py
+++ b/src/mcross/gui/view.py
@@ -71,7 +71,7 @@ class View:
    back_callback = None
    forward_callback = None

    def __init__(self, root: Tk, model: Model, fonts=(None, None)):
    def __init__(self, root: Tk, model: Model, fonts=(None, None), dark=False):
        self.model = model

        # first row - address bar + buttons
@@ -165,8 +165,8 @@ class View:

            font=(text_font, 13),
            bg="#212121" if dark else "#fff8dc",
            fg="#eee" if dark else "black",
            # hide blinking insertion cursor:
@@ -176,12 +176,12 @@ class View:
        text.pack(side="left", fill="both", expand=True)
        text.tag_config("link", foreground="brown")
        text.tag_config("link", foreground="#ff8a65" if dark else "brown")
        text.tag_bind("link", "<Enter>", self._on_link_enter)
        text.tag_bind("link", "<Leave>", self._on_link_leave)
        text.tag_bind("link", "<Button-1>", self._on_link_click)
        text.tag_config("pre", font=(mono_font, 13))
        text.tag_config("listitem", foreground="#044604")
        text.tag_config("listitem", foreground="#64c664" if dark else "#044604")

        base_heading_font = font.Font(font=text["font"])
Looks good to me. Merging it now, thanks!

However you probably shouldn't put too much effort into cosmetic 
personalization for now, since I plan to implement some sort of conf 
file / cli arg configuration scheme which will be more granular
(--h1-font, --h1-color, --list-size etc.)