feat: display human-readable file sizes

This commit is contained in:
lohhiiccc 2026-07-02 19:32:29 +02:00
parent a48a13b1fd
commit 9a1d620556

View file

@ -38,6 +38,17 @@ class UI:
item = items[index]
self._render_item(stdscr, item, index, index + self.HEADER_ROWS, width)
SIZE_UNITS = ("", "K", "M", "G", "T", "P")
@staticmethod
def _format_size(size: int) -> str:
value = float(size)
for unit in UI.SIZE_UNITS:
if value < 1024:
return str(int(value)) if unit == "" else f"{value:.1f}{unit}"
value /= 1024
return f"{value:.1f}E"
ARROW = " -> "
ARROW_LEN = len(ARROW)
@ -59,7 +70,7 @@ class UI:
stdscr.addstr(row, name_len, self.ARROW, attr_arrow)
stdscr.addstr(row, name_len + self.ARROW_LEN, str(item.point_to), attr_target)
stdscr.addstr(row, col_width, str(size).ljust(col_width * 2), attr)
stdscr.addstr(row, col_width, self._format_size(size).ljust(col_width * 2), attr)
stdscr.addstr(row, col_width * 2, stat.filemode(perm), attr)
@property