res-theme: non-interactive apply mode (res-theme apply) #15

Closed
opened 2026-07-27 19:34:43 +00:00 by agent · 1 comment
Member

Goal

res-theme currently only runs as an interactive TUI editor for the theme config. Add a non-interactive mode so it can be called from scripts, .bashrc, session starters, and cron jobs to apply the current theme to the terminal.

Design

CLI interface

res-theme apply          # read config, emit OSC, exit
res-theme reset          # emit reset OSC, exit
res-theme                # (no args) launch interactive TUI (existing behavior)

res-theme apply

  1. Load theme config via theme.LoadConfig() (follows the normal waterfall: defaults → /etc~/.config)
  2. Call theme.InitTheme(cfg) to populate the package-level palette variables
  3. Emit OSC sequences to stdout:
    • OSC 10/11 (fg/bg) via theme.ApplyConsolePalette(os.Stdout) — safe for shell sessions
    • Optionally OSC 4 (16-color palette remap) via theme.ApplyPalette(os.Stdout) with a --full flag
  4. Exit 0

The default behavior (apply without --full) uses ApplyConsolePalette (fg/bg only) because that's what's safe for general shell use — remapping all 16 ANSI colors would break child process colors.

res-theme reset

Call theme.ResetPalette(os.Stdout) and exit.

Flags

  • --full — use ApplyPalette (full 16-color remap) instead of ApplyConsolePalette (fg/bg only). Only applies to apply.

Non-interactive detection

When args are present (apply, reset), skip the bubbletea TUI entirely and go straight to the OSC emit path. This avoids the alt-screen setup cost and keeps the terminal clean.

Files to change

File Change
core/cmd/res-theme/main.go Add CLI arg parsing before TUI launch; apply and reset subcommands short-circuit to OSC emit

Verification

  1. go build ./cmd/res-theme/
  2. go vet ./cmd/res-theme/
  3. Run res-theme apply in a terminal → should see fg/bg change to amber
  4. Run res-theme reset → should restore terminal defaults
  5. Run res-theme (no args) → should launch interactive TUI as before
  6. go test ./... still passes

Notes

  • The OSC emit path already exists in the theme package (ApplyPalette, ApplyConsolePalette, ResetPalette). This is just wiring a CLI entry point to it.
  • No config changes needed — theme.LoadConfig() already handles the waterfall.
  • Consider adding res-theme apply to session startup docs (e.g. docs/init-design.md or a new docs/theme.md).
## Goal `res-theme` currently only runs as an interactive TUI editor for the theme config. Add a non-interactive mode so it can be called from scripts, `.bashrc`, session starters, and cron jobs to apply the current theme to the terminal. ## Design ### CLI interface ``` res-theme apply # read config, emit OSC, exit res-theme reset # emit reset OSC, exit res-theme # (no args) launch interactive TUI (existing behavior) ``` ### `res-theme apply` 1. Load theme config via `theme.LoadConfig()` (follows the normal waterfall: defaults → `/etc` → `~/.config`) 2. Call `theme.InitTheme(cfg)` to populate the package-level palette variables 3. Emit OSC sequences to stdout: - OSC 10/11 (fg/bg) via `theme.ApplyConsolePalette(os.Stdout)` — safe for shell sessions - Optionally OSC 4 (16-color palette remap) via `theme.ApplyPalette(os.Stdout)` with a `--full` flag 4. Exit 0 The default behavior (`apply` without `--full`) uses `ApplyConsolePalette` (fg/bg only) because that's what's safe for general shell use — remapping all 16 ANSI colors would break child process colors. ### `res-theme reset` Call `theme.ResetPalette(os.Stdout)` and exit. ### Flags - `--full` — use `ApplyPalette` (full 16-color remap) instead of `ApplyConsolePalette` (fg/bg only). Only applies to `apply`. ### Non-interactive detection When args are present (`apply`, `reset`), skip the bubbletea TUI entirely and go straight to the OSC emit path. This avoids the alt-screen setup cost and keeps the terminal clean. ## Files to change | File | Change | |------|--------| | `core/cmd/res-theme/main.go` | Add CLI arg parsing before TUI launch; `apply` and `reset` subcommands short-circuit to OSC emit | ## Verification 1. `go build ./cmd/res-theme/` 2. `go vet ./cmd/res-theme/` 3. Run `res-theme apply` in a terminal → should see fg/bg change to amber 4. Run `res-theme reset` → should restore terminal defaults 5. Run `res-theme` (no args) → should launch interactive TUI as before 6. `go test ./...` still passes ## Notes - The OSC emit path already exists in the theme package (`ApplyPalette`, `ApplyConsolePalette`, `ResetPalette`). This is just wiring a CLI entry point to it. - No config changes needed — `theme.LoadConfig()` already handles the waterfall. - Consider adding `res-theme apply` to session startup docs (e.g. `docs/init-design.md` or a new `docs/theme.md`).
agent closed this issue 2026-08-03 18:07:07 +00:00
Author
Member

Implemented non-interactive apply and reset subcommands:

  • res-theme apply — loads config, emits OSC 10/11 (fg/bg), exits
  • res-theme apply --full — loads config, emits OSC 4 (full 16-color remap), exits
  • res-theme reset — emits reset OSC, exits
  • res-theme (no args) — launches interactive TUI as before

Build and tests pass.

Implemented non-interactive `apply` and `reset` subcommands: - `res-theme apply` — loads config, emits OSC 10/11 (fg/bg), exits - `res-theme apply --full` — loads config, emits OSC 4 (full 16-color remap), exits - `res-theme reset` — emits reset OSC, exits - `res-theme` (no args) — launches interactive TUI as before Build and tests pass.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
residual/.agent#15
No description provided.