Class: Shellfie::Config
- Inherits:
-
Object
- Object
- Shellfie::Config
- Includes:
- ConfigValidation
- Defined in:
- lib/shellfie/config.rb
Constant Summary collapse
- VALID_THEMES =
ThemeRegistry.available_themes.freeze
- VALID_OVERFLOW_MODES =
%w[clip wrap scroll].freeze
- VALID_CURSOR_STYLES =
%w[block bar underline].freeze
- VALID_PALETTES =
%w[global adaptive theme].freeze
- VALID_SCROLL_EASINGS =
%w[linear ease_in ease_out ease_in_out].freeze
- DEFAULTS =
deep_freeze(deep_dup(ConfigDefaults::VALUES))
Instance Attribute Summary collapse
-
#animation ⇒ Object
readonly
Returns the value of attribute animation.
-
#color_scheme ⇒ Object
readonly
Returns the value of attribute color_scheme.
-
#colors ⇒ Object
readonly
Returns the value of attribute colors.
-
#cursor ⇒ Object
readonly
Returns the value of attribute cursor.
-
#font ⇒ Object
readonly
Returns the value of attribute font.
-
#frames ⇒ Object
readonly
Returns the value of attribute frames.
-
#headless ⇒ Object
readonly
Returns the value of attribute headless.
-
#limits ⇒ Object
readonly
Returns the value of attribute limits.
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
-
#theme ⇒ Object
readonly
Returns the value of attribute theme.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
-
#window ⇒ Object
readonly
Returns the value of attribute window.
-
#window_decoration ⇒ Object
readonly
Returns the value of attribute window_decoration.
-
#window_theme ⇒ Object
readonly
Returns the value of attribute window_theme.
Class Method Summary collapse
Instance Method Summary collapse
- #animated? ⇒ Boolean
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
- #static? ⇒ Boolean
- #to_h ⇒ Object
Methods included from ConfigValidation
Constructor Details
#initialize(options = {}) ⇒ Config
Returns a new instance of Config.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/shellfie/config.rb', line 60 def initialize( = {}) = self.class.normalize_keys() merged = merge_defaults() @version = merged[:version] @theme = merged[:theme] @window_theme = merged[:window_theme] @color_scheme = merged[:color_scheme] @colors = merged[:colors] @window_decoration = merged[:window_decoration] @title = merged[:title] || "Terminal" @window = merged[:window] @font = merged[:font] @lines = merged[:lines] || [] @animation = merged[:animation] @frames = merged[:frames] || [] @cursor = merged[:cursor] @limits = merged[:limits] @headless = merged[:headless] || false validate! freeze_state! end |
Instance Attribute Details
#animation ⇒ Object (readonly)
Returns the value of attribute animation.
57 58 59 |
# File 'lib/shellfie/config.rb', line 57 def animation @animation end |
#color_scheme ⇒ Object (readonly)
Returns the value of attribute color_scheme.
57 58 59 |
# File 'lib/shellfie/config.rb', line 57 def color_scheme @color_scheme end |
#colors ⇒ Object (readonly)
Returns the value of attribute colors.
57 58 59 |
# File 'lib/shellfie/config.rb', line 57 def colors @colors end |
#cursor ⇒ Object (readonly)
Returns the value of attribute cursor.
57 58 59 |
# File 'lib/shellfie/config.rb', line 57 def cursor @cursor end |
#font ⇒ Object (readonly)
Returns the value of attribute font.
57 58 59 |
# File 'lib/shellfie/config.rb', line 57 def font @font end |
#frames ⇒ Object (readonly)
Returns the value of attribute frames.
57 58 59 |
# File 'lib/shellfie/config.rb', line 57 def frames @frames end |
#headless ⇒ Object (readonly)
Returns the value of attribute headless.
57 58 59 |
# File 'lib/shellfie/config.rb', line 57 def headless @headless end |
#limits ⇒ Object (readonly)
Returns the value of attribute limits.
57 58 59 |
# File 'lib/shellfie/config.rb', line 57 def limits @limits end |
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
57 58 59 |
# File 'lib/shellfie/config.rb', line 57 def lines @lines end |
#theme ⇒ Object (readonly)
Returns the value of attribute theme.
57 58 59 |
# File 'lib/shellfie/config.rb', line 57 def theme @theme end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
57 58 59 |
# File 'lib/shellfie/config.rb', line 57 def title @title end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
57 58 59 |
# File 'lib/shellfie/config.rb', line 57 def version @version end |
#window ⇒ Object (readonly)
Returns the value of attribute window.
57 58 59 |
# File 'lib/shellfie/config.rb', line 57 def window @window end |
#window_decoration ⇒ Object (readonly)
Returns the value of attribute window_decoration.
57 58 59 |
# File 'lib/shellfie/config.rb', line 57 def window_decoration @window_decoration end |
#window_theme ⇒ Object (readonly)
Returns the value of attribute window_theme.
57 58 59 |
# File 'lib/shellfie/config.rb', line 57 def window_theme @window_theme end |
Class Method Details
.deep_dup(value) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/shellfie/config.rb', line 19 def deep_dup(value) case value when Hash value.each_with_object({}) { |(key, nested_value), result| result[key] = deep_dup(nested_value) } when Array value.map { |nested_value| deep_dup(nested_value) } else value end end |
.deep_freeze(value) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/shellfie/config.rb', line 30 def deep_freeze(value) case value when Hash value.each_value { |nested_value| deep_freeze(nested_value) } when Array value.each { |nested_value| deep_freeze(nested_value) } end value.freeze end |
.normalize_keys(value) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/shellfie/config.rb', line 40 def normalize_keys(value) case value when Hash value.each_with_object({}) do |(key, nested_value), result| normalized_key = key.is_a?(String) ? key.to_sym : key result[normalized_key] = normalize_keys(nested_value) end when Array value.map { |nested_value| normalize_keys(nested_value) } else value end end |
Instance Method Details
#animated? ⇒ Boolean
87 88 89 |
# File 'lib/shellfie/config.rb', line 87 def animated? !static? end |
#static? ⇒ Boolean
83 84 85 |
# File 'lib/shellfie/config.rb', line 83 def static? @frames.empty? end |
#to_h ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/shellfie/config.rb', line 91 def to_h { version: version, theme: theme, window_theme: window_theme, color_scheme: color_scheme, colors: colors, window_decoration: window_decoration, title: title, window: window, font: font, animation: animation, cursor: cursor, limits: limits, headless: headless, lines: lines.map(&:to_h), frames: frames.map(&:to_h) } end |