Browse Source

Remove status truncate from wait and calculate max length in the progress writer based on the terminal width

Signed-off-by: aiordache <[email protected]>
aiordache 5 năm trước cách đây
mục cha
commit
4add3a1662
2 tập tin đã thay đổi với 10 bổ sung12 xóa
  1. 2 11
      ecs/wait.go
  2. 8 1
      progress/tty.go

+ 2 - 11
ecs/wait.go

@@ -74,8 +74,7 @@ func (b *ecsAPIService) WaitStackCompletion(ctx context.Context, name string, op
 			knownEvents[*event.EventId] = struct{}{}
 
 			resource := aws.StringValue(event.LogicalResourceId)
-			reason := shortenMessage(
-				aws.StringValue(event.ResourceStatusReason))
+			reason := aws.StringValue(event.ResourceStatusReason)
 			status := aws.StringValue(event.ResourceStatus)
 			progressStatus := progress.Working
 
@@ -116,21 +115,13 @@ func (b *ecsAPIService) WaitStackCompletion(ctx context.Context, name string, op
 			}
 			stackErr = err
 			operation = stackDelete
-			reason := shortenMessage(err.Error())
 			w.Event(progress.Event{
 				ID:         name,
 				Status:     progress.Error,
-				StatusText: reason,
+				StatusText: err.Error(),
 			})
 		}
 	}
 
 	return stackErr
 }
-
-func shortenMessage(message string) string {
-	if len(message) < 30 {
-		return message
-	}
-	return message[:30] + "..."
-}

+ 8 - 1
progress/tty.go

@@ -146,12 +146,19 @@ func lineText(event Event, terminalWidth, statusPadding int, color bool) string
 	if padding < 0 {
 		padding = 0
 	}
+	// calculate the max length for the status text, on errors it
+	// is 2-3 lines long and breaks the line formating
+	maxStatusLen := terminalWidth - textLen - statusPadding - 15
+	status := event.StatusText
+	if len(status) > maxStatusLen {
+		status = status[:maxStatusLen] + "..."
+	}
 	text := fmt.Sprintf(" %s %s %s%s %s",
 		event.spinner.String(),
 		event.ID,
 		event.Text,
 		strings.Repeat(" ", padding),
-		event.StatusText,
+		status,
 	)
 	timer := fmt.Sprintf("%.1fs\n", elapsed)
 	o := align(text, timer, terminalWidth)