Skip to content

Commit

Permalink
Clamp progress bar inputs (NethermindEth#7235)
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams authored Jul 2, 2024
1 parent 699b3b5 commit 7d8c4c0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Nethermind/Nethermind.Logging/Progress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ private static string[] CreateChunks(char ch, string start, string end)

public static string GetMeter(float value, int max)
{
float progressF = value / max * WidthBar;
float progressF = Math.Clamp(value / max, 0, 1) * WidthBar;
int progress = (int)Math.Floor(progressF);
int progressChar = (int)((progressF - progress) * _progressChars.Length);
int progressChar = Math.Clamp((int)((progressF - progress) * _progressChars.Length), 0, _progressChars.Length - 1);
int empty = Math.Clamp(WidthBar - progress - 1, 0, WidthBar);

return string.Concat(_fullChunks[progress], _progressChars[progressChar], _emptyChunks[WidthBar - progress - 1]);
return string.Concat(_fullChunks[progress], _progressChars[progressChar], _emptyChunks[empty]);
}
}

0 comments on commit 7d8c4c0

Please sign in to comment.