Class: Tui::Line

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#backgroundObject

Returns the value of attribute background.



500
501
502
# File 'lib/tui.rb', line 500

def background
  @background
end

#truncateObject

Returns the value of attribute truncate.



500
501
502
# File 'lib/tui.rb', line 500

def truncate
  @truncate
end

Instance Method Details

#centerObject



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

Returns:

  • (Boolean)


529
530
531
# File 'lib/tui.rb', line 529

def has_input?
  @has_input
end

#leftObject



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

#rightObject



525
526
527
# File 'lib/tui.rb', line 525

def right
  @right ||= SegmentWriter.new(z_index: 0)
end

#writeObject



513
514
515
# File 'lib/tui.rb', line 513

def write
  @left
end