Class: Ace::Tmux::Models::LayoutNode

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/tmux/models/layout_node.rb

Overview

A tree node for nested pane layouts.

Either a leaf (wraps a Pane model) or a container (direction + children). Used by LayoutStringBuilder to produce tmux custom layout strings.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(direction: nil, children: [], pane: nil, size: nil) ⇒ LayoutNode

Returns a new instance of LayoutNode.

Parameters:

  • direction (:horizontal, :vertical, nil) (defaults to: nil)

    Split direction (nil for leaf)

  • children (Array<LayoutNode>) (defaults to: [])

    Child nodes (empty for leaf)

  • pane (Models::Pane, nil) (defaults to: nil)

    Pane model (nil for container)

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

    Size hint (e.g., “40%”, “80”)



19
20
21
22
23
24
25
# File 'lib/ace/tmux/models/layout_node.rb', line 19

def initialize(direction: nil, children: [], pane: nil, size: nil)
  @direction = direction
  @children = children
  @pane = pane
  @size = size
  @pane_id = nil
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



12
13
14
# File 'lib/ace/tmux/models/layout_node.rb', line 12

def children
  @children
end

#directionObject (readonly)

Returns the value of attribute direction.



12
13
14
# File 'lib/ace/tmux/models/layout_node.rb', line 12

def direction
  @direction
end

#paneObject (readonly)

Returns the value of attribute pane.



12
13
14
# File 'lib/ace/tmux/models/layout_node.rb', line 12

def pane
  @pane
end

#pane_idObject

Returns the value of attribute pane_id.



13
14
15
# File 'lib/ace/tmux/models/layout_node.rb', line 13

def pane_id
  @pane_id
end

#sizeObject (readonly)

Returns the value of attribute size.



12
13
14
# File 'lib/ace/tmux/models/layout_node.rb', line 12

def size
  @size
end

Instance Method Details

#container?Boolean

Returns true if this node is a container (has direction + children).

Returns:

  • (Boolean)

    true if this node is a container (has direction + children)



33
34
35
# File 'lib/ace/tmux/models/layout_node.rb', line 33

def container?
  !leaf?
end

#leaf?Boolean

Returns true if this node is a leaf (has a pane, no children).

Returns:

  • (Boolean)

    true if this node is a leaf (has a pane, no children)



28
29
30
# File 'lib/ace/tmux/models/layout_node.rb', line 28

def leaf?
  @pane != nil
end

#leaf_countInteger

Returns Total number of leaf panes in this subtree.

Returns:

  • (Integer)

    Total number of leaf panes in this subtree



38
39
40
41
42
# File 'lib/ace/tmux/models/layout_node.rb', line 38

def leaf_count
  return 1 if leaf?

  @children.sum(&:leaf_count)
end

#leavesArray<LayoutNode>

Returns All leaf nodes in DFS left-to-right order.

Returns:

  • (Array<LayoutNode>)

    All leaf nodes in DFS left-to-right order



45
46
47
48
49
# File 'lib/ace/tmux/models/layout_node.rb', line 45

def leaves
  return [self] if leaf?

  @children.flat_map(&:leaves)
end