Class: Ace::Tmux::Organisms::WindowManager

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/tmux/organisms/window_manager.rb

Overview

Orchestrates adding a window to an existing session from a preset

Flow:

1. Detect current session (from $TMUX env or --session flag)
2. Load and resolve window preset
3. Create window in session
4. Set up panes
5. Apply layout

Instance Method Summary collapse

Constructor Details

#initialize(executor:, session_builder:, tmux: "tmux") ⇒ WindowManager

Returns a new instance of WindowManager.

Parameters:



18
19
20
21
22
# File 'lib/ace/tmux/organisms/window_manager.rb', line 18

def initialize(executor:, session_builder:, tmux: "tmux")
  @executor = executor
  @session_builder = session_builder
  @tmux = tmux
end

Instance Method Details

#add_window(preset_name, session: nil, root: nil, name: nil) ⇒ String

Add a window from a preset to a session

Parameters:

  • preset_name (String)

    Window preset name (used as fallback window name)

  • session (String, nil) (defaults to: nil)

    Target session name (nil = detect current)

  • root (String, nil) (defaults to: nil)

    Working directory override

  • name (String, nil) (defaults to: nil)

    Explicit window name override

Returns:

  • (String)

    The effective window name

Raises:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ace/tmux/organisms/window_manager.rb', line 31

def add_window(preset_name, session: nil, root: nil, name: nil)
  target_session = session || detect_current_session
  raise NotInTmuxError, "Not inside a tmux session. Use --session to specify one." unless target_session

  window = @session_builder.build_window(preset_name)
  effective_root = root || window.root
  effective_name = resolve_window_name(name, root, preset_name)

  # Create the window and capture its unique ID
  cmd = Atoms::TmuxCommandBuilder.new_window(
    target_session,
    name: effective_name,
    root: effective_root,
    print_format: '#{window_id}',
    tmux: @tmux
  )
  result = @executor.capture(cmd)
  unless result.success?
    detail = (result.respond_to?(:stderr) && !result.stderr.to_s.empty?) ? ": #{result.stderr.strip}" : ""
    raise "Failed to create window#{detail}"
  end

  window_target = result.stdout.strip
  setup_panes(window, window_target, effective_root)

  effective_name
end