Class: Clacky::UI2::Themes::BaseTheme

Inherits:
Object
  • Object
show all
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

HackerTheme, MinimalTheme

Instance Method Summary collapse

Constructor Details

#initializeBaseTheme

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

#colorsHash

Get all colors defined by this theme

Returns:

  • (Hash)

    Color definitions



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

Returns:

  • (Boolean)

    true if dark background, false if light background



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

Parameters:

  • key (Symbol)

    Symbol key (e.g., :user, :assistant)

Returns:

  • (String)

    Colored symbol



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

Parameters:

  • text (String)

    Text to format

  • key (Symbol)

    Color key (e.g., :user, :assistant)

Returns:

  • (String)

    Colored text



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

#nameString

Theme name for display (subclasses should override)

Returns:

  • (String)

    Theme name

Raises:

  • (NotImplementedError)


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)

Parameters:

  • is_dark (Boolean)

    true if dark background, false if light



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

Parameters:

  • key (Symbol)

    Symbol key

Returns:

  • (String)

    Symbol string



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

Parameters:

  • key (Symbol)

    Color key

Returns:

  • (Symbol)

    Pastel color method name



45
46
47
# File 'lib/clacky/ui2/themes/base_theme.rb', line 45

def symbol_color(key)
  colors.dig(key, 0) || :white
end

#symbolsHash

Get all symbols defined by this theme

Returns:

  • (Hash)

    Symbol definitions



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]

Parameters:

  • key (Symbol)

    Color key

Returns:

  • (Symbol)

    Pastel color method name



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