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.



505
506
507
508
509
510
511
512
513
514
# File 'lib/tui.rb', line 505

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.



503
504
505
# File 'lib/tui.rb', line 503

def background
  @background
end

#truncateObject

Returns the value of attribute truncate.



503
504
505
# File 'lib/tui.rb', line 503

def truncate
  @truncate
end

Instance Method Details

#centerObject



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

def center
  @center ||= SegmentWriter.new(z_index: 2)
end

#cursor_column(input_field, width) ⇒ Object



541
542
543
544
# File 'lib/tui.rb', line 541

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)


532
533
534
# File 'lib/tui.rb', line 532

def has_input?
  @has_input
end

#leftObject



520
521
522
# File 'lib/tui.rb', line 520

def left
  @left
end

#mark_has_input(prefix_width) ⇒ Object



536
537
538
539
# File 'lib/tui.rb', line 536

def mark_has_input(prefix_width)
  @has_input = true
  @input_prefix_width = prefix_width
end

#render(io, width) ⇒ Object



546
547
548
# File 'lib/tui.rb', line 546

def render(io, width)
  render_line(io, width, trailing_newline: true)
end

#render_no_newline(io, width) ⇒ Object



550
551
552
# File 'lib/tui.rb', line 550

def render_no_newline(io, width)
  render_line(io, width, trailing_newline: false)
end

#rightObject



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

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

#writeObject



516
517
518
# File 'lib/tui.rb', line 516

def write
  @left
end