From bc097abc72c40030e8126df2121450dd96b628a2 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 12 Aug 2013 16:55:17 -0700 Subject: [PATCH] packer: Don't output up to \r with remote command, lost anyways --- packer/communicator.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/packer/communicator.go b/packer/communicator.go index 859495cd3..a3bed992f 100644 --- a/packer/communicator.go +++ b/packer/communicator.go @@ -116,9 +116,9 @@ OutputLoop: for { select { case output := <-stderrCh: - ui.Message(strings.TrimSpace(output)) + ui.Message(r.cleanOutputLine(output)) case output := <-stdoutCh: - ui.Message(strings.TrimSpace(output)) + ui.Message(r.cleanOutputLine(output)) case <-exitCh: break OutputLoop } @@ -164,3 +164,19 @@ func (r *RemoteCmd) Wait() { <-r.exitCh } + +// cleanOutputLine cleans up a line so that '\r' don't muck up the +// UI output when we're reading from a remote command. +func (r *RemoteCmd) cleanOutputLine(line string) string { + // Trim surrounding whitespace + line = strings.TrimSpace(line) + + // Trim up to the first carriage return, since that text would be + // lost anyways. + idx := strings.LastIndex(line, "\r") + if idx > -1 { + line = line[idx+1:] + } + + return line +}