Class: TerminalLayout::InputBox
- Inherits:
-
Box
- Object
- Box
- TerminalLayout::InputBox
show all
- Defined in:
- lib/terminal_layout.rb
Instance Attribute Summary collapse
-
#cursor_position ⇒ Object
cursor_position is the actual coordinates on the screen of where then cursor is rendered.
-
#position ⇒ Object
position is the desired X-position of the cursor if everything was displayed on a single line.
Attributes inherited from Box
#children, #computed, #content, #name, #style
Instance Method Summary
collapse
Methods inherited from Box
#find_child_of_type, #height, #inspect, #size, #to_s, #to_str, #width
#_callbacks, #emit, #on, #unsubscribe
Constructor Details
#initialize(*args) ⇒ InputBox
Returns a new instance of InputBox.
450
451
452
453
454
455
456
|
# File 'lib/terminal_layout.rb', line 450
def initialize(*args)
super
@computed = { x: 0, y: 0 }
@cursor_position = OpenStruct.new(x: 0, y: 0)
@position = 0
@focused = false
end
|
Instance Attribute Details
#cursor_position ⇒ Object
cursor_position is the actual coordinates on the screen of where then cursor is rendered
430
431
432
|
# File 'lib/terminal_layout.rb', line 430
def cursor_position
@cursor_position
end
|
#position ⇒ Object
position is the desired X-position of the cursor if everything was displayed on a single line
434
435
436
|
# File 'lib/terminal_layout.rb', line 434
def position
@position
end
|
Instance Method Details
#content=(str) ⇒ Object
466
467
468
469
470
471
472
473
|
# File 'lib/terminal_layout.rb', line 466
def content=(str)
new_content = ANSIString.new(str)
if @content != new_content
old_content = @content
@content = new_content
emit :content_changed, old_content, @content
end
end
|
#cursor_off ⇒ Object
458
459
460
|
# File 'lib/terminal_layout.rb', line 458
def cursor_off
@style.update(cursor: 'none')
end
|
#cursor_on ⇒ Object
462
463
464
|
# File 'lib/terminal_layout.rb', line 462
def cursor_on
@style.update(cursor: 'auto')
end
|
#focus! ⇒ Object
436
437
438
439
440
|
# File 'lib/terminal_layout.rb', line 436
def focus!
return if @focused
@focused = true
emit :focus_changed, !@focused, @focused
end
|
#focused? ⇒ Boolean
448
|
# File 'lib/terminal_layout.rb', line 448
def focused? ; !!@focused ; end
|
#remove_focus! ⇒ Object
442
443
444
445
446
|
# File 'lib/terminal_layout.rb', line 442
def remove_focus!
return unless @focused
@focused = false
emit :focus_changed, !@focused, @focused
end
|
#update_computed(style) ⇒ Object
481
482
483
484
485
486
487
488
489
490
|
# File 'lib/terminal_layout.rb', line 481
def update_computed(style)
if style[:y] && style[:y] > 0
style = style.dup.delete_if { |k,_| [:x, :y].include?(k) }
end
@computed.merge!(style)
end
|