Class: RSpec::Conductor::Util::Terminal

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

Defined Under Namespace

Classes: Box, Line

Constant Summary collapse

INDENTATION_REGEX =
/^(\s+)(.*)$/

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, screen_buffer = ScreenBuffer.new(output)) ⇒ Terminal

Returns a new instance of Terminal.



59
60
61
62
63
# File 'lib/rspec/conductor/util/terminal.rb', line 59

def initialize(output = $stdout, screen_buffer = ScreenBuffer.new(output))
  @output = output
  @screen_buffer = screen_buffer
  @wrapper_box = Box.new(self)
end

Instance Method Details

#boxObject



73
74
75
# File 'lib/rspec/conductor/util/terminal.rb', line 73

def box
  @wrapper_box.box
end

#line(content = "", **kwargs) ⇒ Object



65
66
67
# File 'lib/rspec/conductor/util/terminal.rb', line 65

def line(content = "", **kwargs)
  @wrapper_box.line(content, **kwargs)
end

#puts(content = "", **kwargs) ⇒ Object



69
70
71
# File 'lib/rspec/conductor/util/terminal.rb', line 69

def puts(content = "", **kwargs)
  @wrapper_box.puts(content, **kwargs)
end

#redrawObject



81
82
83
84
# File 'lib/rspec/conductor/util/terminal.rb', line 81

def redraw
  screen_lines = @wrapper_box.lines.flat_map { |line| line.truncate ? truncate_to_tty_width(line.content) : rewrap_to_tty_width(line.content) }
  @screen_buffer.update(screen_lines.take(tty_height(@output) - 1))
end

#scroll_to_bottomObject



77
78
79
# File 'lib/rspec/conductor/util/terminal.rb', line 77

def scroll_to_bottom
  @screen_buffer.scroll_to_bottom
end