Class: TerminalLayout::Box

Inherits:
Object
  • Object
show all
Includes:
EventEmitter
Defined in:
lib/terminal_layout.rb

Direct Known Subclasses

InputBox

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from EventEmitter

#_callbacks, #emit, #on, #unsubscribe

Constructor Details

#initialize(style: {}, children: [], content: "") ⇒ Box

Returns a new instance of Box.



343
344
345
346
347
348
349
350
351
# File 'lib/terminal_layout.rb', line 343

def initialize(style:{}, children:[], content:"")
  @style = style
  @children = children
  @content = ANSIString.new(content)
  @computed = {}

  initialize_defaults
  subscribe_to_events_on_children
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



341
342
343
# File 'lib/terminal_layout.rb', line 341

def children
  @children
end

#computedObject

Returns the value of attribute computed.



341
342
343
# File 'lib/terminal_layout.rb', line 341

def computed
  @computed
end

#contentObject

Returns the value of attribute content.



341
342
343
# File 'lib/terminal_layout.rb', line 341

def content
  @content
end

#nameObject

Returns the value of attribute name.



341
342
343
# File 'lib/terminal_layout.rb', line 341

def name
  @name
end

#styleObject

Returns the value of attribute style.



341
342
343
# File 'lib/terminal_layout.rb', line 341

def style
  @style
end

Instance Method Details

#find_child_of_type(type, &block) ⇒ Object



375
376
377
378
379
380
381
382
383
384
# File 'lib/terminal_layout.rb', line 375

def find_child_of_type(type, &block)
  children.each do |child|
    matches = child.is_a?(type)
    matches &= block.call(child) if matches && block
    return child if matches
    child_matches = child.find_child_of_type(type, &block)
    return child_matches if child_matches
  end
  nil
end

#heightObject



398
399
400
# File 'lib/terminal_layout.rb', line 398

def height
  style[:height]
end

#inspectObject



402
403
404
# File 'lib/terminal_layout.rb', line 402

def inspect
  to_s
end

#positionObject



386
387
388
# File 'lib/terminal_layout.rb', line 386

def position
  Position.new(x, y)
end

#sizeObject



390
391
392
# File 'lib/terminal_layout.rb', line 390

def size
  Dimension.new(width, height)
end

#to_sObject



410
411
412
# File 'lib/terminal_layout.rb', line 410

def to_s
  "<#{self.class}##{object_id} position=(#{x},#{y}) dimensions=#{width}x#{height} display=#{display.inspect} content=#{content} name=#{@name}/>"
end

#to_strObject



406
407
408
# File 'lib/terminal_layout.rb', line 406

def to_str
  to_s
end

#update_computed(style) ⇒ Object



414
415
416
# File 'lib/terminal_layout.rb', line 414

def update_computed(style)
  @computed.merge!(style)
end

#widthObject



394
395
396
# File 'lib/terminal_layout.rb', line 394

def width
  style[:width]
end