Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #22209 - Render empty lines properly in output #380

Merged
merged 4 commits into from Sep 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -44,6 +44,7 @@ div.terminal {
div.line div.content {
position: relative;
margin-left: 50px;
white-space: pre;
}

a {
Expand Down
9 changes: 5 additions & 4 deletions app/helpers/job_invocation_output_helper.rb
@@ -1,4 +1,5 @@
module JobInvocationOutputHelper
COLOR_PATTERN = /\e\[.*?m/
CONSOLE_COLOR = {
'31' => 'red',
'32' => 'lightgreen',
Expand All @@ -17,19 +18,19 @@ module JobInvocationOutputHelper
}.tap { |h| h.default = 'default' }.freeze

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

current_color = 'default'
@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}">}
@current_color = CONSOLE_COLOR[color_index]
out << %{</span><span style="color: #{@current_color}">}
end
else
out << h(console_line)
Expand Down
4 changes: 2 additions & 2 deletions app/views/template_invocations/_output_line_set.html.erb
@@ -1,7 +1,7 @@
<% output_line_set['output'].strip.split("\n").each do |line| %>
<% output_line_set['output'].gsub("\r\n", "\n").split("\n", -1).each do |line| %>
<%= content_tag :div, :class => 'line ' + output_line_set['output_type'], :data => { :timestamp => output_line_set['timestamp'] } do %>

<%= content_tag(:span, (@line_counter += 1).to_s.rjust(4).gsub(' ', '&nbsp;').html_safe + ':', :class => 'counter', :title => (output_line_set['timestamp'] && Time.at(output_line_set['timestamp']))) %>
<%= content_tag(:div, (line.empty? ? '&nbsp;' : colorize_line(line)).html_safe, :class => 'content') %>
<%= content_tag(:div, colorize_line(line.gsub(JobInvocationOutputHelper::COLOR_PATTERN, '').empty? ? "#{line}\n" : line).html_safe, :class => 'content') %>
<% end %>
<% end %>