Class: Gitlab::Ci::Ansi2json::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/ci/ansi2json/converter.rb

Instance Method Summary collapse

Instance Method Details

#convert(stream, new_state) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/gitlab/ci/ansi2json/converter.rb', line 7

def convert(stream, new_state)
  @lines = []
  @state = State.new(new_state, stream.size)

  append = false
  truncated = false

  cur_offset = stream.tell
  if cur_offset > @state.offset
    @state.offset = cur_offset
    truncated = true
  else
    stream.seek(@state.offset)
    append = @state.offset > 0
  end

  start_offset = @state.offset

  @state.new_line!(
    style: Style.new(@state.inherited_style))

  stream.each_line do |line|
    consume_line(line)
  end

  # This must be assigned before flushing the current line
  # or the @current_line.offset will advance to the very end
  # of the trace. Instead we want @last_line_offset to always
  # point to the beginning of last line.
  @state.set_last_line_offset

  flush_current_line

  Gitlab::Ci::Ansi2json::Result.new(
    lines: @lines,
    state: @state.encode,
    append: append,
    truncated: truncated,
    offset: start_offset,
    stream: stream
  )
end