Method: TerminalLayout::Renderer#dumb_render

Defined in:
lib/terminal_layout/renderer.rb

#dumb_render(object, reset: false) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/terminal_layout/renderer.rb', line 99

def dumb_render(object, reset: false)
  Treefell['render'].puts %|\nDUMB RENDER: #{self.class}##{__callee__} reset=#{reset} caller=#{caller[0..5].join("\n")}}|
  if reset
    @y = 0
    @previously_printed_lines.clear
  else
    move_up_n_rows @y
    move_to_beginning_of_row
    @y = 0
  end
  @output.print @term_info.control_string "civis"

  object = find_top_of_tree(object)

  object_width = object.width

  rendered_content = object.render
  printable_content = rendered_content.sub(/\s*\Z/m, '')
  printable_lines = printable_content.split(/\n/).each_with_object([]) do |line, results|
    if line.empty?
      results << line
    else
      results.concat line.scan(/.{1,#{terminal_width}}/)
    end
  end

  i = 0
  fullzip(printable_lines, @previously_printed_lines) do |new_line, previous_line|
    i += 1
    if new_line && new_line != previous_line
      # be sure to reset the terminal at the outset of every line
      # because we don't know what state the previous line ended in
      line2print = "#{new_line}\e[0m"
      term_info.control "el"
      move_to_beginning_of_row
      term_info.control "el"
      @output.puts line2print
      move_to_beginning_of_row
    elsif i <= printable_lines.length
      move_down_n_rows 1
    end
  end

  move_to_beginning_of_row
  clear_screen_down

  # calculate lines drawn so we know where we are
  lines_drawn = (printable_content.length / object_width.to_f).ceil
  @y = lines_drawn

  input_box = object.box.find_child_of_type(InputBox) do |box|
    box.focused?
  end
  render_cursor(input_box)

  @previously_printed_lines = printable_lines
end