feat: display human-readable file sizes
This commit is contained in:
parent
a48a13b1fd
commit
9a1d620556
1 changed files with 12 additions and 1 deletions
13
src/IO/UI.py
13
src/IO/UI.py
|
|
@ -38,6 +38,17 @@ class UI:
|
||||||
item = items[index]
|
item = items[index]
|
||||||
self._render_item(stdscr, item, index, index + self.HEADER_ROWS, width)
|
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 = " -> "
|
||||||
ARROW_LEN = len(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, attr_arrow)
|
||||||
stdscr.addstr(row, name_len + self.ARROW_LEN, str(item.point_to), attr_target)
|
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)
|
stdscr.addstr(row, col_width * 2, stat.filemode(perm), attr)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue