Class: Termplot::Renderers::TextRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/termplot/renderers/text_renderer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bordered_window:, text:, row:, errors:, align: :center) ⇒ TextRenderer

Returns a new instance of TextRenderer.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/termplot/renderers/text_renderer.rb', line 14

def initialize(
  bordered_window:,
  text:,
  row:,
  errors:,
  align: :center
)

  @window = bordered_window
  @text = Termplot::Utils::AnsiSafeString.new(text)
  @row = row
  @errors = errors
  @align = align
end

Instance Attribute Details

#alignObject (readonly)

Returns the value of attribute align.



6
7
8
# File 'lib/termplot/renderers/text_renderer.rb', line 6

def align
  @align
end

#errorsObject (readonly)

Returns the value of attribute errors.



6
7
8
# File 'lib/termplot/renderers/text_renderer.rb', line 6

def errors
  @errors
end

#rowObject (readonly)

Returns the value of attribute row.



6
7
8
# File 'lib/termplot/renderers/text_renderer.rb', line 6

def row
  @row
end

#textObject (readonly)

Returns the value of attribute text.



6
7
8
# File 'lib/termplot/renderers/text_renderer.rb', line 6

def text
  @text
end

#windowObject (readonly)

Returns the value of attribute window.



6
7
8
# File 'lib/termplot/renderers/text_renderer.rb', line 6

def window
  @window
end

Instance Method Details

#renderObject



29
30
31
32
33
34
35
36
37
# File 'lib/termplot/renderers/text_renderer.rb', line 29

def render
  window.cursor.row = row
  window.cursor.beginning_of_line
  window.cursor.forward(position)

  clamped_text.each do |char|
    window.write(char)
  end
end