GitHub - netmute/dol: Detect dark/light mode on the CLI

1 min read Original article ↗

Detect dark/light mode on the CLI.

dol-banner

Why?

Modern operating systems can automatically switch between dark and light mode. However, many CLI tools assume a fixed dark or light background unless told otherwise. This is an attempt to make that less painful.

The output is intentionally minimal; it just prints dark or light. This allows you to construct command lines with it.

Examples:

difft --background $(dol) file1 file2

Installation

Either of these will work.

brew install netmute/tap/dol
mise use -g github:netmute/dol
go install github.com/netmute/dol@latest

How it works

  • dol writes a CSI ? 996 n device status report (DSR) query to the active terminal and expects a reply like CSI ? 997 ; 1 n (dark) or CSI ? 997 ; 2 n (light).
  • If your terminal does not support this query, dol prints an error and exits with status 1.

Terminal support

See this document to check whether your terminal currently supports this feature.