Skip to content

darkmode

stable

Detects the OS dark/light mode preference and accent color on Windows by querying the registry, and provides theme color palettes.

use plugin darkmode::{is_dark_mode, is_light_mode, preferred_theme, …}
9 functions Systems
/ filter jk navigate Esc clear
Functions (9)
  1. is_dark_mode Returns true if OS dark mode is active
  2. is_light_mode Returns true if OS light mode is active
  3. preferred_theme Returns "dark", "light", or "unknown"
  4. color_scheme Returns the CSS color-scheme string
  5. supports_dark_mode Returns true on platforms with detection
  6. accent_color Returns the OS accent color as RGB
  7. system_colors Returns background, foreground, and accent
  8. high_contrast Returns true if high contrast mode is active
  9. theme_colors Returns a full theme color palette

Overview

darkmode reports the operating system's appearance preferences so a Zolo program can adapt its output to match the desktop. Its core concept is detection: every function is a stateless query that reads the current OS theme (dark vs. light), accent color, and accessibility flags, then returns a plain value or color table — there are no handles to manage. Detection is currently implemented on Windows (via registry queries); on other platforms the functions degrade gracefully to neutral defaults. Reach for this plugin when you generate CSS, terminal colors, or HTML and want it to honor the user's system theme.

Common patterns

Pick a palette that matches the live OS theme and print a couple of usable colors:

use plugin darkmode::{preferred_theme, theme_colors}

let theme = preferred_theme()
let colors = theme_colors(theme)
print("theme: {theme}")
print("background: {colors["background"]}")
print("foreground: {colors["foreground"]}")

Emit a CSS snippet that respects both the OS color-scheme and the accent color:

use plugin darkmode::{color_scheme, accent_color}

let scheme = color_scheme()
let a = accent_color()
print(":root {{ color-scheme: {scheme}; --accent: rgb({a["r"]}, {a["g"]}, {a["b"]}); }}")

Branch on accessibility before choosing colors, falling back when detection is unsupported:

use plugin darkmode::{supports_dark_mode, high_contrast, is_dark_mode}

if !supports_dark_mode() {
  print("theme detection unavailable; using defaults")
} else if high_contrast() {
  print("rendering high-contrast palette")
} else if is_dark_mode() {
  print("rendering dark palette")
} else {
  print("rendering light palette")
}

Returns true if OS dark mode is active

Returns true if the operating system is currently in dark mode. On Windows, queries the registry key AppsUseLightTheme. Returns false if detection is unavailable on the current platform.

use plugin darkmode::{is_dark_mode}

if is_dark_mode() {
  print("dark mode active")
} else {
  print("light mode active")
}

Returns true if OS light mode is active

Returns true if dark mode is not active. Equivalent to !is_dark_mode().

use plugin darkmode::{is_light_mode}

if is_light_mode() {
  print("using light theme")
}

Returns "dark", "light", or "unknown"

Returns "dark" or "light" based on the OS setting, or "unknown" if detection is not available on the current platform.

use plugin darkmode::{preferred_theme}

let theme = preferred_theme()
print("theme: {theme}")

Use it to choose a matching palette in one step:

use plugin darkmode::{preferred_theme, theme_colors}

let colors = theme_colors(preferred_theme())
print("surface: {colors["surface"]}")

Returns the CSS color-scheme string

Returns a CSS color-scheme compatible string: "dark", "light", or "no-preference". Useful when generating CSS or HTML from Zolo.

use plugin darkmode::{color_scheme}

let scheme = color_scheme()
print("color-scheme: {scheme}")

Returns true on platforms with detection

Returns true on platforms where dark mode detection is implemented (currently Windows only).

use plugin darkmode::{supports_dark_mode, preferred_theme}

if supports_dark_mode() {
  print("theme: {preferred_theme()}")
} else {
  print("detection not available")
}

Returns the OS accent color as RGB

Returns the OS accent color as {r, g, b} (integer values 0–255). On Windows, reads the AccentColor DWORD from the DWM registry key (ABGR format). Falls back to {r: 0, g: 120, b: 215} (Windows blue) if unavailable.

use plugin darkmode::{accent_color}

let accent = accent_color()
print("accent: rgb({accent["r"]}, {accent["g"]}, {accent["b"]})")

Format the same color as a CSS hex-style declaration:

use plugin darkmode::{accent_color}

let a = accent_color()
print("--accent: rgb({a["r"]} {a["g"]} {a["b"]});")

Returns background, foreground, and accent

Returns a table with background, foreground, and accent fields as hex color strings, reflecting the current OS theme. Dark mode returns dark backgrounds; light mode returns white backgrounds.

use plugin darkmode::{system_colors}

let colors = system_colors()
print("bg: {colors["background"]}")
print("fg: {colors["foreground"]}")
print("accent: {colors["accent"]}")

Returns true if high contrast mode is active

Returns true if the OS high contrast accessibility mode is active. On Windows, checks the HighContrast registry flags. Returns false on other platforms.

use plugin darkmode::{high_contrast}

if high_contrast() {
  print("high contrast mode enabled")
}

Returns a full theme color palette

Returns a color palette for the given theme name ("dark" or "light"). If no argument is provided, uses the current OS theme. Returns background, foreground, surface, and border hex color strings.

use plugin darkmode::{theme_colors}

let dark = theme_colors("dark")
print("dark bg: {dark["background"]}")
print("dark surface: {dark["surface"]}")

let light = theme_colors("light")
print("light border: {light["border"]}")
enespt-br