Module: Fatty::Themes::Resolver

Defined in:
lib/fatty/themes/resolver.rb

Overview

The Resolver module is responsible for transforming a raw theme loaded by the Loader into a fully-resolved "theme_spec".

Resolution includes:

  • applying inheritance between themes
  • applying inheritance between roles
  • filling in default attributes
  • synthesizing "composite" roles used by the alert panel

Composite alert roles (e.g., :alert_info, :alert_warn, etc.) combine the background and structural properties of the :alert role with the foreground and attributes of the semantic roles (:good, :info, :warn, :error).

The result of resolution is a Hash keyed by role names, where each value is a symbolic color specification (typically using color names and attrs). We refer to this Hash as a "theme_spec".

A theme_spec is not directly renderable. Before rendering, it must be "compiled" into a palette by Fatty::Colors::Palette.apply!. The palette maps each role to concrete rendering data (RGB values for truecolor or Curses color pairs, along with attributes).

Renderer classes consume only the compiled palette and never operate directly on the theme_spec. module Resolver

Constant Summary collapse

DEFAULT_ROLE_SPECS =
{
  region: { attrs: [:reverse] },
  cursor: { attrs: [:reverse] },
  input_suggestion: { attrs: [:dim] },
  pager_status: { attrs: [:reverse] },
  search_input: { attrs: [:reverse] },
  match_current: { attrs: [:reverse] },
  match_other: { attrs: [:underline] },
  popup_counts: { attrs: [:bold] },
  alert: { attrs: [:bold] },
  markdown_table_cell: {},
  markdown_underline: { attrs: [:underline] },
  markdown_hrule: { attrs: [:dim] },
  line_number: { attrs: [:dim] },
}.freeze
ROLE_PARENTS =
{
  input: :output,
  input_suggestion: :input,

  region: :output,
  cursor: :input,

  popup: :output,
  popup_frame: :popup,
  popup_input: :input,
  popup_selection: :region,
  popup_counts: :popup,

  search_input: :popup,

  match_current: :region,
  match_other: :region,

  status: :output,
  alert: :output,
  info: :output,
  good: :info,
  warn: :info,
  error: :warn,

  pager_status: :status,
  line_number: :output,

  markdown_h1: :output,
  markdown_h2: :markdown_h1,
  markdown_h3: :markdown_h2,

  markdown_code: :output,
  markdown_code_block: :markdown_code,
  markdown_code_gutter: :markdown_code_block,

  markdown_strong: :output,
  markdown_emphasis: :output,

  markdown_link: :output,
  markdown_url: :markdown_link,

  markdown_quote_gutter: :output,
  markdown_highlight: :output,
  markdown_table_header: :markdown_strong,
  markdown_table_cell: :output,
  markdown_underline: :output,
  markdown_hrule: :output,
}.freeze

Class Method Summary collapse

Class Method Details

.resolve(registry, name) ⇒ Object



104
105
106
107
108
109
110
# File 'lib/fatty/themes/resolver.rb', line 104

def resolve(registry, name)
  raw = merge_theme_chain(registry, name.to_sym, stack: [])
  raw[:roles] = resolve_role_inheritance(raw[:roles])
  raw[:roles] = add_composite_roles(raw[:roles])
  raw[:name] = name.to_sym
  raw
end