Skip to content

Commit db85546

Browse files
neonichuaciidgh
authored andcommitted
Fix progress bar if output exceeds terminal width
This currently messes up the progress bar, this change makes it so that long output gets head truncated with ellipsis.
1 parent 5e07468 commit db85546

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Sources/Utility/ProgressBar.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,13 @@ public final class ProgressBar: ProgressBarProtocol {
122122
term.endLine()
123123

124124
term.clearLine()
125-
term.write(text)
125+
if text.utf8.count > term.width {
126+
let prefix = ""
127+
term.write(prefix)
128+
term.write(String(text.suffix(term.width - prefix.utf8.count)))
129+
} else {
130+
term.write(text)
131+
}
126132

127133
term.moveCursor(up: 1)
128134
}

0 commit comments

Comments
 (0)