Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:1ay1 Agentty Theme Resolution

From Leeroopedia
Knowledge Sources
Domains UI, Theming
Last Updated 2026-10-28 12:00 GMT

Overview

Resolves user appearance preferences into what the renderer actually uses, handling auto-detection, terminal capability clamping, and theme publishing.

Description

The agentty::ui_prefs::resolve module bridges Prefs (what the user WANTS) and Resolved (what they GET), which differs wherever a preference is "auto" or asks for something the terminal cannot do. Keeping the two apart lets the settings panel show the wish and the resolved value side by side ("auto — truecolor").

Resolution: tier from detection unless overridden; polarity from COLORFGBG unless overridden; theme from the built-in scheme table, but only if the terminal can paint it (below 256 colors, a scheme's palette would be quantised into mud, so native is strictly better). `scheme_is_light()` computes luminance for named schemes, returning nullopt for native (no opinion).

The resolved theme is published to TWO sinks: an atomic pointer for agentty's view builders (which pick colors while building the Element tree, before the renderer sees it) and `maya::app_set_theme` for the renderer slot and projected palettes. One entry point means the pair cannot come apart.

Usage

Import this when you need to: resolve prefs into a concrete theme for the renderer, detect terminal capabilities, find a named scheme, or publish the active theme.

Code Reference

Source Location

Signature

namespace agentty::ui_prefs {

struct Resolved {
    const maya::Theme*    theme  = &maya::theme::native;
    maya::theme::ColorTier tier  = maya::theme::ColorTier::Ansi16;
    maya::theme::Polarity  polarity = maya::theme::Polarity::Unknown;
    bool tier_detected    = true;
    bool polarity_detected = true;
};

struct Detected {
    maya::theme::ColorTier tier;
    maya::theme::Polarity  polarity;
};

[[nodiscard]] inline Detected detect(bool tty);           // TERM/COLORTERM/COLORFGBG
[[nodiscard]] inline Resolved resolve(const Prefs& p, const Detected& d);  // PURE
[[nodiscard]] inline const maya::Theme* find_scheme(std::string_view name);  // binary search
[[nodiscard]] inline std::optional<bool> scheme_is_light(const maya::Theme&) noexcept;
[[nodiscard]] inline std::string_view theme_override_reason(const Prefs&, const Resolved&);

// Publish the resolved theme to both sinks (atomic + app_set_theme):
inline void publish_theme(const maya::Theme& t) noexcept;
[[nodiscard]] inline const maya::Theme& theme() noexcept;  // currently in force
}

Import

#include "agentty/domain/ui_theme.hpp"

I/O Contract

Inputs

Name Type Required Description
p Prefs Yes User's appearance preferences
d Detected Yes Terminal's detected capabilities (tier, polarity)
tty bool Yes (detect) Whether stdout is a terminal

Outputs

Name Type Description
Resolved struct Theme pointer, tier, polarity, detection flags
theme() const maya::Theme& The theme in force (atomic load)
theme_override_reason() std::string_view Why the chosen theme is not in use

Usage Examples

Resolve and Publish

#include "agentty/domain/ui_theme.hpp"

auto detected = agentty::ui_prefs::detect(is_tty);
auto resolved  = agentty::ui_prefs::resolve(settings.ui, detected);
// resolved.tier — what the terminal gets
// resolved.theme — which palette to paint with

// Publish to both view builders and renderer:
agentty::ui_prefs::publish_theme(*resolved.theme);

// Check for mismatch:
auto reason = agentty::ui_prefs::theme_override_reason(settings.ui, resolved);
// "dark scheme on a light terminal" or ""

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment