Class: Potty::Theme
- Inherits:
-
Object
- Object
- Potty::Theme
- Defined in:
- lib/potty/theme.rb
Overview
Theme maps semantic names to a render-target-agnostic Style (symbolic colours + attributes). It is pure data — it does NOT touch curses. Each Surface resolves a Style to its concrete form (CursesSurface to a colour pair, InlineSurface to ANSI SGR), which is why a single Theme drives both rendering modes and why every widget that asks the theme for an attribute works in either mode with no per-widget special-casing.
‘style`, `[]`, and `attr` all return a Style — `[]`/`attr` are kept as ergonomic aliases (attr adds bold/underline).
Constant Summary collapse
- COLORS =
Symbolic colour names -> curses colour numbers (-1 = terminal default). Used by CursesSurface when it resolves a Style to a colour pair.
{ default: -1, black: ::Curses::COLOR_BLACK, red: ::Curses::COLOR_RED, green: ::Curses::COLOR_GREEN, yellow: ::Curses::COLOR_YELLOW, blue: ::Curses::COLOR_BLUE, magenta: ::Curses::COLOR_MAGENTA, cyan: ::Curses::COLOR_CYAN, white: ::Curses::COLOR_WHITE, bright_black: 8 }.freeze
- PALETTE =
name -> { fg:, bg: } in symbolic colours. Body text inherits the terminal’s own colours (:default) so potty blends into any theme; only deliberate highlights carry an explicit background.
{ normal: { fg: :default, bg: :default }, selected: { fg: :black, bg: :green }, disabled: { fg: :bright_black, bg: :default }, success: { fg: :green, bg: :default }, error: { fg: :red, bg: :default }, warning: { fg: :yellow, bg: :default }, info: { fg: :cyan, bg: :default }, dim: { fg: :bright_black, bg: :default }, header: { fg: :white, bg: :blue }, status: { fg: :black, bg: :cyan } }.freeze
Instance Attribute Summary collapse
-
#palette ⇒ Object
readonly
Returns the value of attribute palette.
Instance Method Summary collapse
-
#[](name) ⇒ Object
Ergonomic aliases — both return a Style, so widgets can use whichever reads best and still render in any mode.
- #attr(name, bold: false, underline: false) ⇒ Object
-
#initialize(palette = nil) ⇒ Theme
constructor
Pass a partial palette ({ name => { fg:, bg: } }) to override entries.
-
#style(name, bold: false, underline: false, reverse: false) ⇒ Object
Semantic style — symbolic colours + attributes, resolved by a Surface.
Constructor Details
Instance Attribute Details
#palette ⇒ Object (readonly)
Returns the value of attribute palette.
44 45 46 |
# File 'lib/potty/theme.rb', line 44 def palette @palette end |
Instance Method Details
#[](name) ⇒ Object
Ergonomic aliases — both return a Style, so widgets can use whichever reads best and still render in any mode.
59 60 61 |
# File 'lib/potty/theme.rb', line 59 def [](name) style(name) end |
#attr(name, bold: false, underline: false) ⇒ Object
63 64 65 |
# File 'lib/potty/theme.rb', line 63 def attr(name, bold: false, underline: false) style(name, bold: bold, underline: underline) end |
#style(name, bold: false, underline: false, reverse: false) ⇒ Object
Semantic style — symbolic colours + attributes, resolved by a Surface.
52 53 54 55 |
# File 'lib/potty/theme.rb', line 52 def style(name, bold: false, underline: false, reverse: false) c = @palette[name] || @palette[:normal] Style.new(fg: c[:fg], bg: c[:bg], bold: bold, underline: underline, reverse: reverse) end |