fix(TerminalProgress): make the progress bar respect locale-specific decimal separator (#936)

- The `ProgressBar#adjustFormattedSize` function currently expects a
  decimal dot when adding the additional ".0" to the size. This, however,
  breaks when a region with a non-dot decimal separator is used.
This commit is contained in:
TTtie
2025-12-08 18:17:10 +01:00
committed by GitHub
parent 420be748f1
commit ab92f3938e
+3 -2
View File
@@ -261,12 +261,13 @@ extension ProgressBar {
private func adjustFormattedSize(_ size: String) -> String {
// Ensure we always have one digit after the decimal point to prevent flickering.
let zero = Int64(0).formattedSize()
guard !size.contains("."), let first = size.first, first.isNumber || !size.contains(zero) else {
let decimalSep = Locale.current.decimalSeparator ?? "."
guard !size.contains(decimalSep), let first = size.first, first.isNumber || !size.contains(zero) else {
return size
}
var size = size
for unit in ["MB", "GB", "TB"] {
size = size.replacingOccurrences(of: " \(unit)", with: ".0 \(unit)")
size = size.replacingOccurrences(of: " \(unit)", with: "\(decimalSep)0 \(unit)")
}
return size
}