Skip to content

Commit f80c885

Browse files
change loading bar size (#550)
## 📝 Description **What does this PR do and why is this change necessary?** Change the length of the loading bar based on width of terminal. ## ✔️ How to Test ```bash lin obj mb bucketiquette lin obj put file.txt bucketiquette ```
1 parent aae9d2f commit f80c885

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

linodecli/plugins/obj/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
The config of the object storage plugin.
33
"""
4+
import shutil
45

56
ENV_ACCESS_KEY_NAME = "LINODE_CLI_OBJ_ACCESS_KEY"
67
ENV_SECRET_KEY_NAME = "LINODE_CLI_OBJ_SECRET_KEY"
@@ -15,7 +16,8 @@
1516
# for help commands
1617
PLUGIN_BASE = "linode-cli obj"
1718

18-
PROGRESS_BAR_WIDTH = 100
19+
columns = shutil.get_terminal_size(fallback=(80, 24)).columns
20+
PROGRESS_BAR_WIDTH = columns - 20 if columns > 30 else columns
1921

2022
# constant error messages
2123
NO_SCOPES_ERROR = """Your OAuth token isn't authorized to create Object Storage keys.

linodecli/plugins/obj/helpers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ def __call__(self, bytes_amount: int):
2626
if not self.size:
2727
return
2828
self.uploaded += bytes_amount
29-
percentage = self.bar_width * (self.uploaded / self.size)
30-
progress = int(percentage)
29+
percentage = 100 * (self.uploaded / self.size)
30+
uploaded = self.bar_width * (self.uploaded / self.size)
31+
progress = int(uploaded)
3132
progress_bar = ("#" * progress) + ("-" * (self.bar_width - progress))
3233
print(f"\r |{progress_bar}| {percentage:.1f}%", end="\r")
3334
if self.uploaded == self.size:

0 commit comments

Comments
 (0)