Class: Clacky::UI2::ThemeManager
- Inherits:
-
Object
- Object
- Clacky::UI2::ThemeManager
- Defined in:
- lib/clacky/ui2/theme_manager.rb
Overview
ThemeManager handles theme registration and switching
Class Method Summary collapse
- .available_themes ⇒ Object
-
.current_theme ⇒ Object
Delegate methods to instance.
- .instance ⇒ Object
- .register_theme(name, theme_class) ⇒ Object
- .set_theme(name) ⇒ Object
Instance Method Summary collapse
- #available_themes ⇒ Object
- #current_theme ⇒ Object
-
#dark_background? ⇒ Boolean?
Get the detected background mode.
-
#initialize ⇒ ThemeManager
constructor
A new instance of ThemeManager.
- #register_default_themes ⇒ Object
- #register_theme(name, theme_class) ⇒ Object
-
#set_background_mode(is_dark) ⇒ Object
Set the detected terminal background mode This should be called BEFORE UI starts (from CLI).
- #set_theme(name) ⇒ Object
Constructor Details
#initialize ⇒ ThemeManager
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_themes ⇒ Object
25 26 27 |
# File 'lib/clacky/ui2/theme_manager.rb', line 25 def available_themes instance.available_themes end |
.current_theme ⇒ Object
Delegate methods to instance
17 18 19 |
# File 'lib/clacky/ui2/theme_manager.rb', line 17 def current_theme instance.current_theme end |
.instance ⇒ Object
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_themes ⇒ Object
70 71 72 |
# File 'lib/clacky/ui2/theme_manager.rb', line 70 def available_themes @themes.keys end |
#current_theme ⇒ Object
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
53 54 55 |
# File 'lib/clacky/ui2/theme_manager.rb', line 53 def dark_background? @is_dark_background end |
#register_default_themes ⇒ Object
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)
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
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 |