Class: RSpec::Conductor::Util::ScreenBuffer

Inherits:
Object
  • Object
show all
Includes:
ANSI
Defined in:
lib/rspec/conductor/util/screen_buffer.rb

Constant Summary

Constants included from ANSI

ANSI::ANSI_SEQUENCE_REGEX, ANSI::COLOR_CODES, ANSI::VISIBLE_CHAR_GROUP_REGEX

Instance Method Summary collapse

Methods included from ANSI

clear_line, clear_line_forward, color_code, colorize, cursor_back, cursor_column, cursor_down, cursor_end_of_line, cursor_forward, cursor_up, split_visible_char_groups, tty_height, tty_width, visible_chars

Constructor Details

#initialize(output = $stdout) ⇒ ScreenBuffer

Returns a new instance of ScreenBuffer.



9
10
11
12
13
14
15
# File 'lib/rspec/conductor/util/screen_buffer.rb', line 9

def initialize(output = $stdout)
  @output = output
  @lines = []
  @cursor_row = 0
  @cursor_col = 0
  @height = 1
end

Instance Method Details

#scroll_to_bottomObject



34
35
36
# File 'lib/rspec/conductor/util/screen_buffer.rb', line 34

def scroll_to_bottom
  @output.print move_cursor(@height, 0, resize_height: false)
end

#update(new_lines) ⇒ Object

Accepts new state as an array of strings. Computes the minimal diff and writes ANSI escape sequences to @output.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rspec/conductor/util/screen_buffer.rb', line 19

def update(new_lines)
  unless @output.tty?
    @output.puts Array(new_lines).map { |line| visible_chars(line) }
    return
  end

  new_lines = Array(new_lines)
  ops = lines_diff(new_lines)
  unless ops.empty?
    @output.print(ops)
    @output.flush
  end
  @lines = new_lines.dup
end