Class: Shellfie::Config

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ConfigValidation

#validate!

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(options = {})
  options = self.class.normalize_keys(options)
  merged = merge_defaults(options)
  @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

#animationObject (readonly)

Returns the value of attribute animation.



57
58
59
# File 'lib/shellfie/config.rb', line 57

def animation
  @animation
end

#color_schemeObject (readonly)

Returns the value of attribute color_scheme.



57
58
59
# File 'lib/shellfie/config.rb', line 57

def color_scheme
  @color_scheme
end

#colorsObject (readonly)

Returns the value of attribute colors.



57
58
59
# File 'lib/shellfie/config.rb', line 57

def colors
  @colors
end

#cursorObject (readonly)

Returns the value of attribute cursor.



57
58
59
# File 'lib/shellfie/config.rb', line 57

def cursor
  @cursor
end

#fontObject (readonly)

Returns the value of attribute font.



57
58
59
# File 'lib/shellfie/config.rb', line 57

def font
  @font
end

#framesObject (readonly)

Returns the value of attribute frames.



57
58
59
# File 'lib/shellfie/config.rb', line 57

def frames
  @frames
end

#headlessObject (readonly)

Returns the value of attribute headless.



57
58
59
# File 'lib/shellfie/config.rb', line 57

def headless
  @headless
end

#limitsObject (readonly)

Returns the value of attribute limits.



57
58
59
# File 'lib/shellfie/config.rb', line 57

def limits
  @limits
end

#linesObject (readonly)

Returns the value of attribute lines.



57
58
59
# File 'lib/shellfie/config.rb', line 57

def lines
  @lines
end

#themeObject (readonly)

Returns the value of attribute theme.



57
58
59
# File 'lib/shellfie/config.rb', line 57

def theme
  @theme
end

#titleObject (readonly)

Returns the value of attribute title.



57
58
59
# File 'lib/shellfie/config.rb', line 57

def title
  @title
end

#versionObject (readonly)

Returns the value of attribute version.



57
58
59
# File 'lib/shellfie/config.rb', line 57

def version
  @version
end

#windowObject (readonly)

Returns the value of attribute window.



57
58
59
# File 'lib/shellfie/config.rb', line 57

def window
  @window
end

#window_decorationObject (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_themeObject (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

Returns:

  • (Boolean)


87
88
89
# File 'lib/shellfie/config.rb', line 87

def animated?
  !static?
end

#static?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/shellfie/config.rb', line 83

def static?
  @frames.empty?
end

#to_hObject



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