tx.info: display amounts with columnar alignment

This commit is contained in:
The MMGen Project 2022-11-26 18:55:56 +00:00
commit 4da94df0da
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
3 changed files with 14 additions and 10 deletions

View file

@ -36,8 +36,8 @@ class TxInfo(TxInfo):
pink('{:0.6f}%'.format( tx.fee / tx.send_amt * 100 ))
)
def format_abs_fee(self):
return self.tx.proto.coin_amt(self.tx.fee).hl()
def format_abs_fee(self,color,iwidth):
return self.tx.proto.coin_amt(self.tx.fee).fmt(color=color,iwidth=iwidth)
def format_verbose_footer(self):
tx = self.tx
@ -67,6 +67,8 @@ class TxInfo(TxInfo):
key = lambda o: (o.mmid.sort_key if o.mmid else f'+{o.addr}') + f'{o.amt:040.20f}' ),
'raw': lambda: io
}[sort]
if terse:
iwidth = max(len(str(int(e.amt))) for e in io)
for n,e in enumerate(io_sorted()):
if is_input and blockcount:
confs = e.confs + blockcount - tx.blockcount
@ -85,7 +87,7 @@ class TxInfo(TxInfo):
n+1,
e.addr.fmt(color=True,width=addr_w),
mmid_fmt,
e.amt.hl(),
e.amt.fmt(iwidth=iwidth,color=True),
tx.dcoin )
else:
def gen():

View file

@ -55,8 +55,8 @@ class TxInfo(TxInfo):
t_mmid = m['outputs'] if len(tx.outputs) else '',
f_mmid = m['inputs'] )
def format_abs_fee(self):
return self.tx.fee.hl() + (' (max)' if self.tx.txobj['data'] else '')
def format_abs_fee(self,color,iwidth):
return self.tx.fee.fmt(color=color,iwidth=iwidth) + (' (max)' if self.tx.txobj['data'] else '')
def format_rel_fee(self,terse):
return ' ({} of spend amount)'.format(

View file

@ -72,12 +72,14 @@ class TxInfo:
yield self.format_body(blockcount,nonmm_str,max_mmwid,enl,terse=terse,sort=sort)
iwidth = len(str(int(tx.sum_inputs())))
yield self.txinfo_ftr_fs.format(
i = tx.sum_inputs().hl(),
o = tx.sum_outputs().hl(),
C = tx.change.hl(),
s = tx.send_amt.hl(),
a = self.format_abs_fee(),
i = tx.sum_inputs().fmt(color=True,iwidth=iwidth),
o = tx.sum_outputs().fmt(color=True,iwidth=iwidth),
C = tx.change.fmt(color=True,iwidth=iwidth),
s = tx.send_amt.fmt(color=True,iwidth=iwidth),
a = self.format_abs_fee(color=True,iwidth=iwidth),
r = self.format_rel_fee(terse),
d = tx.dcoin,
c = tx.coin )