Skip to content

Commit dac1a9d

Browse files
authored
Merge pull request swiftlang#1939 from hartbit/sr-9647-truncate-redrawing-progress
Simple fix to SR-9647 by truncating redrawing progress text
2 parents 1602f21 + d498b99 commit dac1a9d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Sources/Utility/ProgressAnimation.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,16 @@ public final class RedrawingNinjaProgressAnimation: ProgressAnimationProtocol {
105105
assert(step <= total)
106106

107107
terminal.clearLine()
108-
terminal.write("[\(step)/\(total)] ")
109-
terminal.write(text)
108+
109+
let progressText = "[\(step)/\(total)] \(text)"
110+
if progressText.utf8.count > terminal.width {
111+
let suffix = ""
112+
terminal.write(String(progressText.prefix(terminal.width - suffix.utf8.count)))
113+
terminal.write(suffix)
114+
} else {
115+
terminal.write(progressText)
116+
}
117+
110118
hasDisplayedProgress = true
111119
}
112120

0 commit comments

Comments
 (0)