-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add consistent progress bars for syncing (#7212)
- Loading branch information
Showing
9 changed files
with
141 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using System; | ||
|
||
namespace Nethermind.Logging; | ||
public static class Progress | ||
{ | ||
private const int Width = 40; | ||
private const int WidthBar = Width - 3; | ||
|
||
private static readonly string[] _progressChars = [" ", "⡀", "⡄", "⡆", "⡇", "⣇", "⣧", "⣷", "⣿"]; | ||
private static readonly string[] _fullChunks = CreateChunks('⣿', "[", ""); | ||
private static readonly string[] _emptyChunks = CreateChunks(' ', "", "]"); | ||
|
||
private static string[] CreateChunks(char ch, string start, string end) | ||
{ | ||
var chunks = new string[WidthBar + 1]; | ||
for (int i = 0; i < chunks.Length; i++) | ||
{ | ||
chunks[i] = start + new string(ch, i) + end; | ||
} | ||
|
||
return chunks; | ||
} | ||
|
||
public static string GetMeter(float value, int max) | ||
{ | ||
float progressF = value / max * WidthBar; | ||
int progress = (int)Math.Floor(progressF); | ||
int progressChar = (int)((progressF - progress) * _progressChars.Length); | ||
|
||
return string.Concat(_fullChunks[progress], _progressChars[progressChar], _emptyChunks[WidthBar - progress - 1]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.