Output total transfer size when confirming

This commit is contained in:
Kovid Goyal
2021-09-12 12:41:48 +05:30
parent 7c90812e51
commit 3eee442f28
2 changed files with 19 additions and 0 deletions

View File

@@ -26,6 +26,7 @@ from kitty.typing import KeyEventType
from ..tui.handler import Handler from ..tui.handler import Handler
from ..tui.loop import Loop, debug from ..tui.loop import Loop, debug
from ..tui.operations import styled from ..tui.operations import styled
from ..tui.utils import human_size
_cwd = _home = '' _cwd = _home = ''
debug debug
@@ -304,6 +305,7 @@ class SendManager:
self.current_chunk_uncompressed_sz: Optional[int] = None self.current_chunk_uncompressed_sz: Optional[int] = None
self.prefix = f'\x1b]{FILE_TRANSFER_CODE};id={self.request_id};' self.prefix = f'\x1b]{FILE_TRANSFER_CODE};id={self.request_id};'
self.suffix = '\x1b\\' self.suffix = '\x1b\\'
self.total_size_of_all_files = sum(df.file_size for df in self.files if df.file_size >= 0)
@property @property
def active_file(self) -> Optional[File]: def active_file(self) -> Optional[File]:
@@ -448,6 +450,8 @@ class Send(Handler):
self.print(df.local_path, '', end=' ') self.print(df.local_path, '', end=' ')
self.cmd.styled(df.remote_final_path, fg='red' if df.remote_initial_size > -1 else None) self.cmd.styled(df.remote_final_path, fg='red' if df.remote_initial_size > -1 else None)
self.print() self.print()
self.print(f'Transferring {len(self.manager.files)} files of total size: {human_size(self.manager.total_size_of_all_files)}')
self.print()
self.print_continue_msg() self.print_continue_msg()
def print_continue_msg(self) -> None: def print_continue_msg(self) -> None:

View File

@@ -27,3 +27,18 @@ def get_key_press(allowed: str, default: str) -> str:
finally: finally:
print(set_cursor_visible(True), end='', flush=True) print(set_cursor_visible(True), end='', flush=True)
return response return response
def human_size(size: int, sep: str = ' ') -> str:
""" Convert a size in bytes into a human readable form """
divisor, suffix = 1, "B"
for i, candidate in enumerate(('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB')):
if size < (1 << ((i + 1) * 10)):
divisor, suffix = (1 << (i * 10)), candidate
break
ans = str(size / divisor)
if ans.find(".") > -1:
ans = ans[:ans.find(".")+2]
if ans.endswith('.0'):
ans = ans[:-2]
return ans + sep + suffix