Skip to content
Kward Search API index

Class: Kward::PtyTranscriptNormalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/kward/pty_transcript_normalizer.rb

Overview

Reduces safe, line-oriented PTY redraws to transcript-friendly text.

Defined Under Namespace

Classes: Line

Constant Summary collapse

HORIZONTAL_REDRAW_PATTERN =
/\r|\e\[[0-9;]*[CDGK`]/.freeze

Class Method Summary collapse

Class Method Details

.normalize(text) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/kward/pty_transcript_normalizer.rb', line 9

def self.normalize(text)
  text.split("\n", -1).map do |line|
    if line.match?(HORIZONTAL_REDRAW_PATTERN)
      Line.new(line).render
    else
      ANSI.sanitize_transcript(line)
    end
  end.join("\n")
end