Class: RawLine::DomTree

Inherits:
TerminalLayout::Box
  • Object
show all
Defined in:
lib/rawline/dom_tree.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(children: nil) ⇒ DomTree

Returns a new instance of DomTree.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rawline/dom_tree.rb', line 9

def initialize(children: nil)
  unless children
    @prompt_box = TerminalLayout::Box.new(content: "default-prompt>", style: {display: :inline})
    @input_box = TerminalLayout::InputBox.new(content: "", style: {display: :inline})
    @content_box = TerminalLayout::Box.new(content: "", style: {display: :block})
    super(style: {}, children: [@prompt_box, @input_box, @content_box])
  else
    super(style: {}, children: children)
    @input_box = find_child_of_type(TerminalLayout::InputBox)
  end
  focus_input_box(@input_box)
end

Instance Attribute Details

#content_boxObject

Returns the value of attribute content_box.



5
6
7
# File 'lib/rawline/dom_tree.rb', line 5

def content_box
  @content_box
end

#focused_input_boxObject

Returns the value of attribute focused_input_box.



7
8
9
# File 'lib/rawline/dom_tree.rb', line 7

def focused_input_box
  @focused_input_box
end

#input_boxObject

Returns the value of attribute input_box.



5
6
7
# File 'lib/rawline/dom_tree.rb', line 5

def input_box
  @input_box
end

#prompt_boxObject

Returns the value of attribute prompt_box.



5
6
7
# File 'lib/rawline/dom_tree.rb', line 5

def prompt_box
  @prompt_box
end

Instance Method Details

#focus_input_box(box) ⇒ Object



22
23
24
25
26
# File 'lib/rawline/dom_tree.rb', line 22

def focus_input_box(box)
  @focused_input_box.remove_focus! if @focused_input_box
  @focused_input_box = box
  @focused_input_box.focus! if @focused_input_box
end