Skip to content

Commit

Permalink
Merge pull request #2971 from zendesk/grosser/cursor
Browse files Browse the repository at this point in the history
better ignore cursor movement for less spammy docker builds
  • Loading branch information
grosser authored Oct 2, 2018
2 parents 0094eb6 + 996038b commit 1c58b48
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion app/models/terminal_executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#
class TerminalExecutor
SECRET_PREFIX = "secret://"
CURSOR = /\e\[\d*[ABCDK]/

attr_reader :pid, :pgid, :output, :timeout

Expand Down Expand Up @@ -104,13 +105,19 @@ def timeout_execution(time, &block)
def stream(from:, to:)
from.each(256) do |chunk|
chunk.scrub!
chunk = chunk.gsub(/\r\e\[\d+[ABCD]\r\n/, "\r") # ignore cursor movement http://ascii-table.com/ansi-escape-sequences.php
ignore_cursor_movement!(chunk)
to.write chunk
end
rescue Errno::EIO
nil # output was closed ... only happens on linux
end

# http://ascii-table.com/ansi-escape-sequences.php
def ignore_cursor_movement!(chunk)
chunk.gsub!(/\r#{CURSOR}\r\n/, "\r")
chunk.gsub!(CURSOR, "")
end

def script(commands)
commands.map! do |c|
if @verbose
Expand Down
4 changes: 2 additions & 2 deletions test/models/terminal_executor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@
end

it "does not log cursor movement ... special output coming from docker builds" do
assert subject.execute("ruby -e 'puts \"Hello\\r\e[1B\\nWorld\\n\"'")
output.string.must_equal "Hello\rWorld\r\n"
assert subject.execute("ruby -e 'puts \"Hello\\r\e[1B\\nWorld\\n\e[1K\"'")
output.string.must_equal "Hello\rWorld\r\n\r\n"
end

describe "with script-executor" do
Expand Down

0 comments on commit 1c58b48

Please sign in to comment.