Class: Mxup::Config
- Inherits:
-
Object
- Object
- Mxup::Config
- Defined in:
- lib/mxup/config.rb
Overview
Parsed mxup YAML config. Pure data; no tmux or filesystem side effects.
Profiles (optional): a config may declare a ‘profiles:` map where each entry is a partial override on top of the base `setup`, `windows`, and `layouts`. A single active profile is resolved at parse time and its overrides are merged in before the rest of the Config is built — so the rest of the system (Launcher, Reconciler, StatusView…) never has to know about profiles.
Instance Attribute Summary collapse
-
#default_profile ⇒ Object
readonly
Returns the value of attribute default_profile.
-
#layout_names ⇒ Object
readonly
Returns the value of attribute layout_names.
-
#layouts ⇒ Object
readonly
Returns the value of attribute layouts.
-
#profile ⇒ Object
readonly
Returns the value of attribute profile.
-
#profile_names ⇒ Object
readonly
Returns the value of attribute profile_names.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
-
#setup ⇒ Object
readonly
Returns the value of attribute setup.
-
#windows ⇒ Object
readonly
Returns the value of attribute windows.
Instance Method Summary collapse
- #default_layout ⇒ Object
-
#effective_window_order(layout_name) ⇒ Object
Returns an ordered list of entries describing how windows should appear in tmux under the given layout.
-
#find_group_for_window(layout_name, window_name) ⇒ Object
Returns [group, index_within_group] or nil.
- #groups_for(layout_name) ⇒ Object
-
#initialize(path, profile: nil) ⇒ Config
constructor
A new instance of Config.
- #window_by_name(name) ⇒ Object
Constructor Details
#initialize(path, profile: nil) ⇒ Config
Returns a new instance of Config.
19 20 21 22 23 24 25 26 |
# File 'lib/mxup/config.rb', line 19 def initialize(path, profile: nil) raw = YAML.safe_load(File.read(path), permitted_classes: [Symbol]) resolve_profile!(raw, profile) @session = raw.fetch('session') @setup = raw['setup']&.strip @windows = parse_windows(raw.fetch('windows')) @layouts, @layout_names = parse_layouts(raw['layouts']) end |
Instance Attribute Details
#default_profile ⇒ Object (readonly)
Returns the value of attribute default_profile.
16 17 18 |
# File 'lib/mxup/config.rb', line 16 def default_profile @default_profile end |
#layout_names ⇒ Object (readonly)
Returns the value of attribute layout_names.
16 17 18 |
# File 'lib/mxup/config.rb', line 16 def layout_names @layout_names end |
#layouts ⇒ Object (readonly)
Returns the value of attribute layouts.
16 17 18 |
# File 'lib/mxup/config.rb', line 16 def layouts @layouts end |
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
16 17 18 |
# File 'lib/mxup/config.rb', line 16 def profile @profile end |
#profile_names ⇒ Object (readonly)
Returns the value of attribute profile_names.
16 17 18 |
# File 'lib/mxup/config.rb', line 16 def profile_names @profile_names end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
16 17 18 |
# File 'lib/mxup/config.rb', line 16 def session @session end |
#setup ⇒ Object (readonly)
Returns the value of attribute setup.
16 17 18 |
# File 'lib/mxup/config.rb', line 16 def setup @setup end |
#windows ⇒ Object (readonly)
Returns the value of attribute windows.
16 17 18 |
# File 'lib/mxup/config.rb', line 16 def windows @windows end |
Instance Method Details
#default_layout ⇒ Object
28 29 30 |
# File 'lib/mxup/config.rb', line 28 def default_layout @layout_names.first end |
#effective_window_order(layout_name) ⇒ Object
Returns an ordered list of entries describing how windows should appear in tmux under the given layout. Each entry is one of:
{ type: :group, name: <group name>, group: PaneGroup }
{ type: :standalone, name: <window name> }
41 42 43 44 45 46 47 48 49 |
# File 'lib/mxup/config.rb', line 41 def effective_window_order(layout_name) groups = groups_for(layout_name) grouped = groups.flat_map(&:window_names).to_set entries = groups.map { |g| { type: :group, name: g.name, group: g } } @windows.each do |w| entries << { type: :standalone, name: w.name } unless grouped.include?(w.name) end entries end |
#find_group_for_window(layout_name, window_name) ⇒ Object
Returns [group, index_within_group] or nil.
56 57 58 59 60 61 62 |
# File 'lib/mxup/config.rb', line 56 def find_group_for_window(layout_name, window_name) groups_for(layout_name).each do |g| idx = g.window_names.index(window_name) return [g, idx] if idx end nil end |
#groups_for(layout_name) ⇒ Object
32 33 34 35 |
# File 'lib/mxup/config.rb', line 32 def groups_for(layout_name) return [] if layout_name.nil? @layouts.fetch(layout_name) end |
#window_by_name(name) ⇒ Object
51 52 53 |
# File 'lib/mxup/config.rb', line 51 def window_by_name(name) @windows.find { |w| w.name == name } end |