commit ab6473739c0c724b21282da00ce6c0483a750ed9
parent ebc544e9729213f81655291b1dfd344047de871f
Author: archiveanon <>
Date: Sun, 7 Apr 2024 09:12:48 +0000
Trim name for smaller terminals
Diffstat:
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/gofile/api.py b/src/gofile/api.py
@@ -5,6 +5,7 @@ import collections
import enum
import os
import pathlib
+import textwrap
from typing import Generic, Iterator, Optional, TypeVar
import msgspec
@@ -120,9 +121,15 @@ def upload_single(
if folder_id:
post_data["folderId"] = folder_id
+ # automatically shorten long file names in small terminals (e.g. split panes)
+ termsize = os.get_terminal_size()
+ short_file_name = textwrap.shorten(
+ file.name, width=int(termsize.columns * 0.6), placeholder=f"…{file.suffix}"
+ )
+
file_size = file.stat().st_size
with tqdm.tqdm(
- desc=file.name,
+ desc=short_file_name,
total=file_size,
unit="B",
unit_scale=True,