Class: Prompts::Content

Inherits:
Object
  • Object
show all
Defined in:
lib/prompts/content.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width: MAX_WIDTH) ⇒ Content

Returns a new instance of Content.



7
8
9
10
11
# File 'lib/prompts/content.rb', line 7

def initialize(width: MAX_WIDTH)
  @slots = []
  @frame_stack = []
  @width = width
end

Instance Attribute Details

#slotsObject (readonly)

Returns the value of attribute slots.



5
6
7
# File 'lib/prompts/content.rb', line 5

def slots
  @slots
end

Instance Method Details

#box(padded: false, border_color: nil) {|box| ... } ⇒ Object

Yields:



24
25
26
27
28
29
# File 'lib/prompts/content.rb', line 24

def box(padded: false, border_color: nil, &block)
  box = Box.new(width: @width, padded: padded, border_color: border_color)
  yield(box)
  @slots.concat box.lines
  self
end

#gapObject



19
20
21
22
# File 'lib/prompts/content.rb', line 19

def gap
  @slots << SPACE
  self
end

#paragraph(text) ⇒ Object



13
14
15
16
17
# File 'lib/prompts/content.rb', line 13

def paragraph(text)
  paragraph = Paragraph.new(text, width: @width)
  @slots.concat paragraph.lines
  self
end

#prepend(*lines) ⇒ Object



40
41
42
# File 'lib/prompts/content.rb', line 40

def prepend(*lines)
  @slots.unshift(*lines)
end

#renderObject



31
32
33
34
# File 'lib/prompts/content.rb', line 31

def render
  clear_screen
  render_frame
end

#reset!Object



36
37
38
# File 'lib/prompts/content.rb', line 36

def reset!
  @slots = @frame_stack.first.dup
end