Class: Clacky::UI2::ThemeManager

Inherits:
Object
  • Object
show all
Defined in:
lib/clacky/ui2/theme_manager.rb

Overview

ThemeManager handles theme registration and switching

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeThemeManager

Returns a new instance of ThemeManager.



34
35
36
37
38
39
40
# File 'lib/clacky/ui2/theme_manager.rb', line 34

def initialize
  @themes = {}
  @current_theme = nil
  @is_dark_background = nil  # Store detected background mode
  register_default_themes
  set_theme(:hacker)
end

Class Method Details

.available_themesObject



25
26
27
# File 'lib/clacky/ui2/theme_manager.rb', line 25

def available_themes
  instance.available_themes
end

.current_themeObject

Delegate methods to instance



17
18
19
# File 'lib/clacky/ui2/theme_manager.rb', line 17

def current_theme
  instance.current_theme
end

.instanceObject



12
13
14
# File 'lib/clacky/ui2/theme_manager.rb', line 12

def instance
  @instance ||= new
end

.register_theme(name, theme_class) ⇒ Object



29
30
31
# File 'lib/clacky/ui2/theme_manager.rb', line 29

def register_theme(name, theme_class)
  instance.register_theme(name, theme_class)
end

.set_theme(name) ⇒ Object



21
22
23
# File 'lib/clacky/ui2/theme_manager.rb', line 21

def set_theme(name)
  instance.set_theme(name)
end

Instance Method Details

#available_themesObject



70
71
72
# File 'lib/clacky/ui2/theme_manager.rb', line 70

def available_themes
  @themes.keys
end

#current_themeObject



57
58
59
# File 'lib/clacky/ui2/theme_manager.rb', line 57

def current_theme
  @current_theme
end

#dark_background?Boolean?

Get the detected background mode

Returns:

  • (Boolean, nil)

    true if dark, false if light, nil if not detected



53
54
55
# File 'lib/clacky/ui2/theme_manager.rb', line 53

def dark_background?
  @is_dark_background
end

#register_default_themesObject



79
80
81
82
# File 'lib/clacky/ui2/theme_manager.rb', line 79

def register_default_themes
  register_theme(:hacker, Themes::HackerTheme)
  register_theme(:minimal, Themes::MinimalTheme)
end

#register_theme(name, theme_class) ⇒ Object



74
75
76
# File 'lib/clacky/ui2/theme_manager.rb', line 74

def register_theme(name, theme_class)
  @themes[name.to_sym] = theme_class
end

#set_background_mode(is_dark) ⇒ Object

Set the detected terminal background mode This should be called BEFORE UI starts (from CLI)

Parameters:

  • is_dark (Boolean)

    true if dark background, false if light



45
46
47
48
49
# File 'lib/clacky/ui2/theme_manager.rb', line 45

def set_background_mode(is_dark)
  @is_dark_background = is_dark
  # Pass to current theme if already initialized
  @current_theme&.set_background_mode(is_dark)
end

#set_theme(name) ⇒ Object

Raises:

  • (ArgumentError)


61
62
63
64
65
66
67
68
# File 'lib/clacky/ui2/theme_manager.rb', line 61

def set_theme(name)
  name = name.to_sym
  raise ArgumentError, "Unknown theme: #{name}" unless @themes.key?(name)

  @current_theme = @themes[name].new
  # Pass background mode to new theme if already detected
  @current_theme.set_background_mode(@is_dark_background) unless @is_dark_background.nil?
end