@@ -117,9 +117,10 @@ public final class RedrawingNinjaProgressAnimation: ProgressAnimationProtocol {
117
117
terminal. clearLine ( )
118
118
119
119
let progressText = " [ \( step) / \( total) ] \( text) "
120
- if progressText. utf8. count > terminal. width {
120
+ let width = terminal. width
121
+ if progressText. utf8. count > width {
121
122
let suffix = " … "
122
- terminal. write ( String ( progressText. prefix ( terminal . width - suffix. utf8. count) ) )
123
+ terminal. write ( String ( progressText. prefix ( width - suffix. utf8. count) ) )
123
124
terminal. write ( suffix)
124
125
} else {
125
126
terminal. write ( progressText)
@@ -211,8 +212,9 @@ public final class RedrawingLitProgressAnimation: ProgressAnimationProtocol {
211
212
public func update( step: Int , total: Int , text: String ) {
212
213
assert ( step <= total)
213
214
215
+ let width = terminal. width
214
216
if !hasDisplayedHeader {
215
- let spaceCount = terminal . width / 2 - header. utf8. count / 2
217
+ let spaceCount = width / 2 - header. utf8. count / 2
216
218
terminal. write ( repeating ( string: " " , count: spaceCount) )
217
219
terminal. write ( header, inColor: . cyan, bold: true )
218
220
terminal. endLine ( )
@@ -225,18 +227,18 @@ public final class RedrawingLitProgressAnimation: ProgressAnimationProtocol {
225
227
let prefix = " \( paddedPercentage) % " + terminal. wrap ( " [ " , inColor: . green, bold: true )
226
228
terminal. write ( prefix)
227
229
228
- let barWidth = terminal . width - prefix. utf8. count
230
+ let barWidth = width - prefix. utf8. count
229
231
let n = Int ( Double ( barWidth) * Double( percentage) / 100.0 )
230
232
231
233
terminal. write ( repeating ( string: " = " , count: n) + repeating( string: " - " , count: barWidth - n) , inColor: . green)
232
234
terminal. write ( " ] " , inColor: . green, bold: true )
233
235
terminal. endLine ( )
234
236
235
237
terminal. clearLine ( )
236
- if text. utf8. count > terminal . width {
238
+ if text. utf8. count > width {
237
239
let prefix = " … "
238
240
terminal. write ( prefix)
239
- terminal. write ( String ( text. suffix ( terminal . width - prefix. utf8. count) ) )
241
+ terminal. write ( String ( text. suffix ( width - prefix. utf8. count) ) )
240
242
} else {
241
243
terminal. write ( text)
242
244
}
0 commit comments