Class: Clacky::UI2::Themes::BaseTheme
- Inherits:
-
Object
- Object
- Clacky::UI2::Themes::BaseTheme
- Defined in:
- lib/clacky/ui2/themes/base_theme.rb
Overview
BaseTheme defines the abstract interface for all themes Subclasses MUST define SYMBOLS and COLORS constants
Direct Known Subclasses
Instance Method Summary collapse
-
#colors ⇒ Hash
Get all colors defined by this theme.
-
#dark_background? ⇒ Boolean
Check if terminal has dark background Uses pre-detected value from ThemeManager, or defaults to true.
-
#format_symbol(key) ⇒ String
Format symbol with its color.
-
#format_text(text, key) ⇒ String
Format text with color for given key.
-
#initialize ⇒ BaseTheme
constructor
A new instance of BaseTheme.
-
#name ⇒ String
Theme name for display (subclasses should override).
-
#set_background_mode(is_dark) ⇒ Object
Set background mode (called by ThemeManager after detection).
-
#symbol(key) ⇒ String
Get symbol for a specific key.
-
#symbol_color(key) ⇒ Symbol
Get symbol color for a specific key.
-
#symbols ⇒ Hash
Get all symbols defined by this theme.
-
#text_color(key) ⇒ Symbol
Get text color for a specific key Automatically selects appropriate color based on terminal background Color format: [symbol_color, dark_bg_text_color, light_bg_text_color].
-
#validate_theme_definition! ⇒ Object
Validate that subclass has defined required constants.
Constructor Details
#initialize ⇒ BaseTheme
Returns a new instance of BaseTheme.
11 12 13 14 15 |
# File 'lib/clacky/ui2/themes/base_theme.rb', line 11 def initialize @pastel = Pastel.new @is_dark_background = nil # Will be set by ThemeManager validate_theme_definition! end |
Instance Method Details
#colors ⇒ Hash
Get all colors defined by this theme
31 32 33 |
# File 'lib/clacky/ui2/themes/base_theme.rb', line 31 def colors self.class::COLORS end |
#dark_background? ⇒ Boolean
Check if terminal has dark background Uses pre-detected value from ThemeManager, or defaults to true
86 87 88 89 |
# File 'lib/clacky/ui2/themes/base_theme.rb', line 86 def dark_background? # Use pre-detected value if available, otherwise default to dark @is_dark_background.nil? ? true : @is_dark_background end |
#format_symbol(key) ⇒ String
Format symbol with its color
65 66 67 |
# File 'lib/clacky/ui2/themes/base_theme.rb', line 65 def format_symbol(key) @pastel.public_send(symbol_color(key), symbol(key)) end |
#format_text(text, key) ⇒ String
Format text with color for given key
73 74 75 |
# File 'lib/clacky/ui2/themes/base_theme.rb', line 73 def format_text(text, key) @pastel.public_send(text_color(key), text) end |
#name ⇒ String
Theme name for display (subclasses should override)
79 80 81 |
# File 'lib/clacky/ui2/themes/base_theme.rb', line 79 def name raise NotImplementedError, "Subclass must implement #name method" end |
#set_background_mode(is_dark) ⇒ Object
Set background mode (called by ThemeManager after detection)
19 20 21 |
# File 'lib/clacky/ui2/themes/base_theme.rb', line 19 def set_background_mode(is_dark) @is_dark_background = is_dark end |
#symbol(key) ⇒ String
Get symbol for a specific key
38 39 40 |
# File 'lib/clacky/ui2/themes/base_theme.rb', line 38 def symbol(key) symbols[key] || "[??]" end |
#symbol_color(key) ⇒ Symbol
Get symbol color for a specific key
45 46 47 |
# File 'lib/clacky/ui2/themes/base_theme.rb', line 45 def symbol_color(key) colors.dig(key, 0) || :white end |
#symbols ⇒ Hash
Get all symbols defined by this theme
25 26 27 |
# File 'lib/clacky/ui2/themes/base_theme.rb', line 25 def symbols self.class::SYMBOLS end |
#text_color(key) ⇒ Symbol
Get text color for a specific key Automatically selects appropriate color based on terminal background Color format: [symbol_color, dark_bg_text_color, light_bg_text_color]
54 55 56 57 58 59 60 |
# File 'lib/clacky/ui2/themes/base_theme.rb', line 54 def text_color(key) color_def = colors[key] return :white unless color_def # Use index 1 for dark background, index 2 for light background dark_background? ? color_def[1] : color_def[2] end |
#validate_theme_definition! ⇒ Object
Validate that subclass has defined required constants
93 94 95 96 97 98 99 100 101 |
# File 'lib/clacky/ui2/themes/base_theme.rb', line 93 def validate_theme_definition! unless self.class.const_defined?(:SYMBOLS) raise NotImplementedError, "Theme #{self.class.name} must define SYMBOLS constant" end unless self.class.const_defined?(:COLORS) raise NotImplementedError, "Theme #{self.class.name} must define COLORS constant" end end |