Class: Tui::Line
- Inherits:
-
Object
- Object
- Tui::Line
- Defined in:
- lib/tui.rb
Instance Attribute Summary collapse
-
#background ⇒ Object
Returns the value of attribute background.
-
#truncate ⇒ Object
Returns the value of attribute truncate.
Instance Method Summary collapse
- #center ⇒ Object
- #cursor_column(input_field, width) ⇒ Object
- #has_input? ⇒ Boolean
-
#initialize(screen, background:, truncate: true) ⇒ Line
constructor
A new instance of Line.
- #left ⇒ Object
- #mark_has_input(prefix_width) ⇒ Object
- #render(io, width) ⇒ Object
- #render_no_newline(io, width) ⇒ Object
- #right ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(screen, background:, truncate: true) ⇒ Line
Returns a new instance of Line.
502 503 504 505 506 507 508 509 510 511 |
# File 'lib/tui.rb', line 502 def initialize(screen, background:, truncate: true) @screen = screen @background = background @truncate = truncate @left = SegmentWriter.new(z_index: 1) @center = nil # Lazy - only created when accessed (z_index: 2, renders on top) @right = nil # Lazy - only created when accessed (z_index: 0) @has_input = false @input_prefix_width = 0 end |
Instance Attribute Details
#background ⇒ Object
Returns the value of attribute background.
500 501 502 |
# File 'lib/tui.rb', line 500 def background @background end |
#truncate ⇒ Object
Returns the value of attribute truncate.
500 501 502 |
# File 'lib/tui.rb', line 500 def truncate @truncate end |
Instance Method Details
#center ⇒ Object
521 522 523 |
# File 'lib/tui.rb', line 521 def center @center ||= SegmentWriter.new(z_index: 2) end |
#cursor_column(input_field, width) ⇒ Object
538 539 540 541 |
# File 'lib/tui.rb', line 538 def cursor_column(input_field, width) # Calculate cursor position: prefix + cursor position in input @input_prefix_width + input_field.cursor + 1 end |
#has_input? ⇒ Boolean
529 530 531 |
# File 'lib/tui.rb', line 529 def has_input? @has_input end |
#left ⇒ Object
517 518 519 |
# File 'lib/tui.rb', line 517 def left @left end |
#mark_has_input(prefix_width) ⇒ Object
533 534 535 536 |
# File 'lib/tui.rb', line 533 def mark_has_input(prefix_width) @has_input = true @input_prefix_width = prefix_width end |
#render(io, width) ⇒ Object
543 544 545 |
# File 'lib/tui.rb', line 543 def render(io, width) render_line(io, width, trailing_newline: true) end |
#render_no_newline(io, width) ⇒ Object
547 548 549 |
# File 'lib/tui.rb', line 547 def render_no_newline(io, width) render_line(io, width, trailing_newline: false) end |
#right ⇒ Object
525 526 527 |
# File 'lib/tui.rb', line 525 def right @right ||= SegmentWriter.new(z_index: 0) end |
#write ⇒ Object
513 514 515 |
# File 'lib/tui.rb', line 513 def write @left end |