Class: Chamomile::Widgets::Text

Inherits:
Object
  • Object
show all
Defined in:
lib/chamomile/frame.rb

Overview

Plain text block.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content: "") ⇒ Text

Returns a new instance of Text.



100
101
102
# File 'lib/chamomile/frame.rb', line 100

def initialize(content: "")
  @content = content
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



98
99
100
# File 'lib/chamomile/frame.rb', line 98

def content
  @content
end

Instance Method Details

#render(width: 80, height: 24) ⇒ Object



104
105
106
107
108
# File 'lib/chamomile/frame.rb', line 104

def render(width: 80, height: 24)
  lines = @content.split("\n", -1)
  lines = lines[0, height] if lines.length > height
  lines.map { |l| l.length > width ? l[0, width] : l }.join("\n")
end