Skip to content

Commit 1c58b48

Browse files
authored
Merge pull request #2971 from zendesk/grosser/cursor
better ignore cursor movement for less spammy docker builds
2 parents 0094eb6 + 996038b commit 1c58b48

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

app/models/terminal_executor.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#
1616
class TerminalExecutor
1717
SECRET_PREFIX = "secret://"
18+
CURSOR = /\e\[\d*[ABCDK]/
1819

1920
attr_reader :pid, :pgid, :output, :timeout
2021

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

115+
# http://ascii-table.com/ansi-escape-sequences.php
116+
def ignore_cursor_movement!(chunk)
117+
chunk.gsub!(/\r#{CURSOR}\r\n/, "\r")
118+
chunk.gsub!(CURSOR, "")
119+
end
120+
114121
def script(commands)
115122
commands.map! do |c|
116123
if @verbose

test/models/terminal_executor_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@
129129
end
130130

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

136136
describe "with script-executor" do

0 commit comments

Comments
 (0)