packer: Don't output up to \r with remote command, lost anyways

This commit is contained in:
Mitchell Hashimoto 2013-08-12 16:55:17 -07:00
parent 856f27bc9b
commit bc097abc72
1 changed files with 18 additions and 2 deletions

View File

@ -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
}