Sha256: c7d2a7994b77516d39ed8749f743c1b28be87edaa04cec845c8e5a66921428f8

Contents?: true

Size: 1.09 KB

Versions: 120

Compression:

Stored size: 1.09 KB

Contents

module JobInvocationOutputHelper
  COLOR_PATTERN = /\e\[.*?m/.freeze
  CONSOLE_COLOR = {
    '31' => 'red',
    '32' => 'lightgreen',
    '33' => 'orange',
    '34' => 'deepskyblue',
    '35' => 'mediumpurple',
    '36' => 'cyan',
    '37' => 'grey',
    '91' => 'red',
    '92' => 'lightgreen',
    '93' => 'yellow',
    '94' => 'lightblue',
    '95' => 'violet',
    '96' => 'turquoise',
    '0'  => 'default',
  }.tap { |h| h.default = 'default' }.freeze

  def colorize_line(line)
    line = line.gsub(COLOR_PATTERN) do |seq|
      color = seq[/(\d+)m/,1]
      "{{{format color:#{color}}}}"
    end

    @current_color ||= 'default'
    out = %{<span style="color: #{@current_color}">}
    parts = line.split(/({{{format.*?}}})/)
    parts.each do |console_line|
      if console_line.include?('{{{format')
        if (color_index = console_line[/color:(\d+)/, 1]).present?
          @current_color = CONSOLE_COLOR[color_index]
          out << %{</span><span style="color: #{@current_color}">}
        end
      else
        out << h(console_line)
      end
    end
    out << %{</span>}
    out
  end
end

Version data entries

120 entries across 120 versions & 1 rubygems

Version Path
foreman_remote_execution-14.1.2 app/helpers/job_invocation_output_helper.rb
foreman_remote_execution-14.1.1 app/helpers/job_invocation_output_helper.rb
foreman_remote_execution-14.1.0 app/helpers/job_invocation_output_helper.rb
foreman_remote_execution-14.0.2 app/helpers/job_invocation_output_helper.rb
foreman_remote_execution-14.0.1 app/helpers/job_invocation_output_helper.rb
foreman_remote_execution-13.2.6 app/helpers/job_invocation_output_helper.rb
foreman_remote_execution-14.0.0 app/helpers/job_invocation_output_helper.rb
foreman_remote_execution-13.2.5 app/helpers/job_invocation_output_helper.rb
foreman_remote_execution-13.2.4 app/helpers/job_invocation_output_helper.rb
foreman_remote_execution-13.2.3 app/helpers/job_invocation_output_helper.rb
foreman_remote_execution-13.2.2 app/helpers/job_invocation_output_helper.rb
foreman_remote_execution-12.0.7 app/helpers/job_invocation_output_helper.rb
foreman_remote_execution-13.2.1 app/helpers/job_invocation_output_helper.rb
foreman_remote_execution-13.2.0 app/helpers/job_invocation_output_helper.rb
foreman_remote_execution-10.1.3 app/helpers/job_invocation_output_helper.rb
foreman_remote_execution-13.0.0 app/helpers/job_invocation_output_helper.rb
foreman_remote_execution-12.0.5 app/helpers/job_invocation_output_helper.rb
foreman_remote_execution-12.0.4 app/helpers/job_invocation_output_helper.rb
foreman_remote_execution-12.0.1 app/helpers/job_invocation_output_helper.rb
foreman_remote_execution-12.0.2 app/helpers/job_invocation_output_helper.rb