Class: Charming::Presentation::Components::TextArea
- Inherits:
-
Charming::Presentation::Component
- Object
- View
- Charming::Presentation::Component
- Charming::Presentation::Components::TextArea
- Defined in:
- lib/charming/presentation/components/text_area.rb
Instance Attribute Summary collapse
-
#cursor ⇒ Object
readonly
Returns the value of attribute cursor.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#preferred_column ⇒ Object
readonly
Returns the value of attribute preferred_column.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #handle_key(event) ⇒ Object
-
#initialize(value: "", placeholder: "", width: nil, height: nil, cursor: nil, offset: 0, preferred_column: nil) ⇒ TextArea
constructor
A new instance of TextArea.
- #render ⇒ Object
Methods inherited from View
Constructor Details
#initialize(value: "", placeholder: "", width: nil, height: nil, cursor: nil, offset: 0, preferred_column: nil) ⇒ TextArea
Returns a new instance of TextArea.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/charming/presentation/components/text_area.rb', line 9 def initialize(value: "", placeholder: "", width: nil, height: nil, cursor: nil, offset: 0, preferred_column: nil) super() @value = value.dup @placeholder = placeholder @width = width @height = height @cursor = cursor || @value.length @offset = offset @preferred_column = preferred_column clamp_position ensure_cursor_visible end |
Instance Attribute Details
#cursor ⇒ Object (readonly)
Returns the value of attribute cursor.
7 8 9 |
# File 'lib/charming/presentation/components/text_area.rb', line 7 def cursor @cursor end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
7 8 9 |
# File 'lib/charming/presentation/components/text_area.rb', line 7 def offset @offset end |
#preferred_column ⇒ Object (readonly)
Returns the value of attribute preferred_column.
7 8 9 |
# File 'lib/charming/presentation/components/text_area.rb', line 7 def preferred_column @preferred_column end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
7 8 9 |
# File 'lib/charming/presentation/components/text_area.rb', line 7 def value @value end |
Instance Method Details
#handle_key(event) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/charming/presentation/components/text_area.rb', line 22 def handle_key(event) key = Charming.key_of(event) return :handled if newline_event?(event) && insert("\n") return :handled if character_event?(event) && insert(event.char) case key when :left then move_left when :right then move_right when :up then move_up when :down then move_down when :home then move_home when :end then move_end when :backspace then delete_before_cursor when :delete then delete_at_cursor when :page_up then page_up when :page_down then page_down else return nil end :handled end |
#render ⇒ Object
44 45 46 |
# File 'lib/charming/presentation/components/text_area.rb', line 44 def render visible_lines.map { |line| render_line(line) }.join("\n") end |