fix: add padding to size in list

This commit is contained in:
Daylin Morgan 2023-08-30 12:00:42 -05:00
parent 4cdfb4fc50
commit cb7d90f0e1
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F

View file

@ -985,7 +985,7 @@ class ViVenv:
size = float( size = float(
sum(p.stat().st_size for p in Path(self.path).rglob("*") if p.is_file()) sum(p.stat().st_size for p in Path(self.path).rglob("*") if p.is_file())
) )
for unit in ("B", "K", "M", "G", "T"): for unit in ("", "K", "M", "G", "T"):
if size < 1024: if size < 1024:
break break
size /= 1024 size /= 1024
@ -1022,7 +1022,7 @@ class ViVenv:
finally: finally:
self.set_path(_path) self.set_path(_path)
def show(self) -> None: def show(self, size_pad: int) -> None:
_id = ( _id = (
self.meta.id[:8] self.meta.id[:8]
if self.meta.id == self.name if self.meta.id == self.name
@ -1031,7 +1031,7 @@ class ViVenv:
size = getattr(self, "size", None) size = getattr(self, "size", None)
line = [] line = []
if size: if size:
line.append(f"""{a.yellow}{size}{a.end}""") line.append(f"""{a.yellow}{size:>{size_pad}}{a.end}""")
line.extend( line.extend(
( (
@ -1448,9 +1448,12 @@ class Viv:
sys.stdout.write("\n".join((vivenv.meta.id for vivenv in vivenvs)) + "\n") sys.stdout.write("\n".join((vivenv.meta.id for vivenv in vivenvs)) + "\n")
sys.exit(0) sys.exit(0)
# NOTE: this feels out of place
size_pad = 0
if size: if size:
for vivenv in vivenvs: for vivenv in vivenvs:
vivenv.get_size() vivenv.get_size()
size_pad = max(size_pad, len(vivenv.size))
if len(self._cache.vivenvs) == 0: if len(self._cache.vivenvs) == 0:
log.info("no vivenvs setup") log.info("no vivenvs setup")
@ -1465,7 +1468,7 @@ class Viv:
) )
else: else:
for vivenv in vivenvs: for vivenv in vivenvs:
vivenv.show() vivenv.show(size_pad)
def cmd_exe(self, vivenv_id: str, cmd: str, rest: List[str]) -> None: def cmd_exe(self, vivenv_id: str, cmd: str, rest: List[str]) -> None:
"""\ """\