From 89f59eff9cc5987f72b351480fd11071f9db72a7 Mon Sep 17 00:00:00 2001 From: Adam Ruzicka Date: Tue, 18 Sep 2018 15:26:08 +0200 Subject: [PATCH 1/4] Fixes #22209 - Render empty lines properly in output For some reason the output uses CRLF to mark a newline, writing CRs into the terminal window led to line numbers not matching the lines. Also we were splitting the output on newlines and trailing empty fields were omitted. --- app/views/template_invocations/_output_line_set.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/template_invocations/_output_line_set.html.erb b/app/views/template_invocations/_output_line_set.html.erb index a246b9db6..61f547659 100644 --- a/app/views/template_invocations/_output_line_set.html.erb +++ b/app/views/template_invocations/_output_line_set.html.erb @@ -1,4 +1,4 @@ -<% 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(' ', ' ').html_safe + ':', :class => 'counter', :title => (output_line_set['timestamp'] && Time.at(output_line_set['timestamp']))) %> From 2fbc6757a20f68647748608d2d7ea0e1517b69aa Mon Sep 17 00:00:00 2001 From: Adam Ruzicka Date: Wed, 19 Sep 2018 10:17:32 +0200 Subject: [PATCH 2/4] Fixes #22209 - Render color lines properly in output There was an issue when line had color information but was otherwise empty. Also multiple consecutive spaces were removed by the browser due to missing css property. --- .../foreman_remote_execution/template_invocation.css.scss | 1 + app/helpers/job_invocation_output_helper.rb | 5 +++-- app/views/template_invocations/_output_line_set.html.erb | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/foreman_remote_execution/template_invocation.css.scss b/app/assets/stylesheets/foreman_remote_execution/template_invocation.css.scss index 38e7dd103..8ca4617b5 100644 --- a/app/assets/stylesheets/foreman_remote_execution/template_invocation.css.scss +++ b/app/assets/stylesheets/foreman_remote_execution/template_invocation.css.scss @@ -44,6 +44,7 @@ div.terminal { div.line div.content { position: relative; margin-left: 50px; + white-space: pre; } a { diff --git a/app/helpers/job_invocation_output_helper.rb b/app/helpers/job_invocation_output_helper.rb index ce565865c..7cf12d3ed 100644 --- a/app/helpers/job_invocation_output_helper.rb +++ b/app/helpers/job_invocation_output_helper.rb @@ -1,4 +1,5 @@ module JobInvocationOutputHelper + COLOR_PATTERN = /\e\[.*?m/.freeze CONSOLE_COLOR = { '31' => 'red', '32' => 'lightgreen', @@ -17,13 +18,13 @@ 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' - out = %{} + out = %{} parts = line.split(/({{{format.*?}}})/) parts.each do |console_line| if console_line.include?('{{{format') diff --git a/app/views/template_invocations/_output_line_set.html.erb b/app/views/template_invocations/_output_line_set.html.erb index 61f547659..d3d21197c 100644 --- a/app/views/template_invocations/_output_line_set.html.erb +++ b/app/views/template_invocations/_output_line_set.html.erb @@ -2,6 +2,6 @@ <%= 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(' ', ' ').html_safe + ':', :class => 'counter', :title => (output_line_set['timestamp'] && Time.at(output_line_set['timestamp']))) %> - <%= content_tag(:div, (line.empty? ? ' ' : colorize_line(line)).html_safe, :class => 'content') %> + <%= content_tag(:div, (line.gsub(JobInvocationOutputHelper::COLOR_PATTERN, '').empty? ? ' ' : colorize_line(line)).html_safe, :class => 'content') %> <% end %> <% end %> From e8b41d3c39efb28d466f98d27d8c01eac5570198 Mon Sep 17 00:00:00 2001 From: Adam Ruzicka Date: Wed, 19 Sep 2018 10:19:06 +0200 Subject: [PATCH 3/4] Fixes #22209 - Make hound happy --- app/helpers/job_invocation_output_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/job_invocation_output_helper.rb b/app/helpers/job_invocation_output_helper.rb index 7cf12d3ed..ff5b11937 100644 --- a/app/helpers/job_invocation_output_helper.rb +++ b/app/helpers/job_invocation_output_helper.rb @@ -1,5 +1,5 @@ module JobInvocationOutputHelper - COLOR_PATTERN = /\e\[.*?m/.freeze + COLOR_PATTERN = /\e\[.*?m/ CONSOLE_COLOR = { '31' => 'red', '32' => 'lightgreen', From 510d2e869107603628065a58af6c5bed69341559 Mon Sep 17 00:00:00 2001 From: Adam Ruzicka Date: Wed, 19 Sep 2018 11:13:38 +0200 Subject: [PATCH 4/4] Fixes #22209 - Fix multi-line color rendering --- app/helpers/job_invocation_output_helper.rb | 8 ++++---- app/views/template_invocations/_output_line_set.html.erb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/helpers/job_invocation_output_helper.rb b/app/helpers/job_invocation_output_helper.rb index ff5b11937..3468d18a0 100644 --- a/app/helpers/job_invocation_output_helper.rb +++ b/app/helpers/job_invocation_output_helper.rb @@ -23,14 +23,14 @@ def colorize_line(line) "{{{format color:#{color}}}}" end - current_color = 'default' - out = %{} + @current_color ||= 'default' + out = %{} 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 << %{} + @current_color = CONSOLE_COLOR[color_index] + out << %{} end else out << h(console_line) diff --git a/app/views/template_invocations/_output_line_set.html.erb b/app/views/template_invocations/_output_line_set.html.erb index d3d21197c..7fb0cac60 100644 --- a/app/views/template_invocations/_output_line_set.html.erb +++ b/app/views/template_invocations/_output_line_set.html.erb @@ -2,6 +2,6 @@ <%= 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(' ', ' ').html_safe + ':', :class => 'counter', :title => (output_line_set['timestamp'] && Time.at(output_line_set['timestamp']))) %> - <%= content_tag(:div, (line.gsub(JobInvocationOutputHelper::COLOR_PATTERN, '').empty? ? ' ' : 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 %>