Skip to content

Commit fd540c8

Browse files
committed
prevent light theme selection for yazi if terminal background is dark
1 parent 7c157e2 commit fd540c8

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

modules/home-manager/yazi/default.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
stateDir = "${config.xdg.stateHome}/yazi";
1212
# Default flavor for a fresh machine; the theme-switcher plugin overwrites
1313
# this file at runtime, and it's only seeded when absent (below), so a
14-
# rebuild never clobbers a saved selection.
14+
# rebuild never clobbers a saved selection. yazi picks the slot matching the
15+
# terminal's color mode at startup, so `light` is the light-terminal fallback.
1516
defaultThemeToml = pkgs.writeText "yazi-theme-default.toml" ''
1617
[flavor]
1718
dark = "kanagawa-kris"
18-
light = "kanagawa-kris"
19+
light = "kanagawa-lotus"
1920
'';
2021
in
2122
{

modules/home-manager/yazi/theme-switcher.yazi/main.lua

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
-- Kanagawa theme switcher.
22
--
3-
-- Presents a which-key menu of the installed flavors and persists the choice to
3+
-- Presents a which-key menu of the dark flavors and persists the choice to
44
-- yazi's state dir (~/.local/state/yazi/theme.toml, an out-of-store symlink the
55
-- nix config points $XDG_CONFIG_HOME/yazi/theme.toml at). yazi reads
66
-- theme.toml's [flavor] only at startup and offers no live flavor reload, so the
77
-- selection takes effect on the next launch — hence the notify.
8+
--
9+
-- Only the dark flavors are offered here: the choice fills theme.toml's `dark`
10+
-- slot, while the `light` slot is pinned to the light Lotus flavor. yazi detects
11+
-- the terminal's color mode at startup and picks the matching slot, so Lotus is
12+
-- never presented as a manual option — it only activates on a light terminal.
13+
-- (A "light" flavor can't repaint a dark terminal: yazi paints widget bgs only,
14+
-- so the file-list body shows the terminal background regardless.)
815

916
local THEMES = {
1017
{ on = "k", flavor = "kanagawa-kris", desc = "Kanagawa Kris" },
1118
{ on = "w", flavor = "kanagawa-wave", desc = "Kanagawa Wave" },
1219
{ on = "d", flavor = "kanagawa-dragon", desc = "Kanagawa Dragon" },
13-
{ on = "l", flavor = "kanagawa-lotus", desc = "Kanagawa Lotus (light)" },
1420
}
1521

1622
-- Resolve ~/.local/state/yazi, honoring XDG_STATE_HOME. os.getenv is pure (no
@@ -37,7 +43,9 @@ return {
3743

3844
local flavor = THEMES[idx].flavor
3945
local dir = state_dir()
40-
local body = string.format('[flavor]\ndark = "%s"\nlight = "%s"\n', flavor, flavor)
46+
-- Chosen flavor drives the dark slot; light stays pinned to Lotus so yazi
47+
-- auto-selects it only when the terminal is in light mode.
48+
local body = string.format('[flavor]\ndark = "%s"\nlight = "kanagawa-lotus"\n', flavor)
4149

4250
-- Ensure the state dir exists (it normally does, seeded by activation).
4351
fs.create("dir_all", Url(dir))
@@ -55,7 +63,7 @@ return {
5563

5664
ya.notify({
5765
title = "Theme",
58-
content = "Set " .. flavor .. ". Restart yazi to apply.",
66+
content = "Set dark flavor to " .. flavor .. ". Restart yazi to apply.",
5967
timeout = 5,
6068
level = "info",
6169
})

0 commit comments

Comments
 (0)