mmgen-tool listaddresses, twview: formatting fixes
This commit is contained in:
parent
6aca0f2986
commit
e53c9bbf53
3 changed files with 33 additions and 24 deletions
|
|
@ -307,7 +307,7 @@ class BTCAmt(Decimal,Hilite,InitErrors):
|
|||
def fmtc(cls):
|
||||
raise NotImplementedError
|
||||
|
||||
def fmt(self,fs='3.8',color=False,suf=''):
|
||||
def fmt(self,fs='4.8',color=False,suf=''):
|
||||
s = str(int(self)) if int(self) == self else self.normalize().__format__('f')
|
||||
if '.' in fs:
|
||||
p1,p2 = map(int,fs.split('.',1))
|
||||
|
|
|
|||
|
|
@ -731,9 +731,9 @@ def Listaddresses(addrs='',minconf=1,
|
|||
out += [fs.format(
|
||||
mid=MMGenID.fmtc('MMGenID',width=max_mmid_len),
|
||||
addr=CoinAddr.fmtc('ADDRESS'),
|
||||
cmt=TwComment.fmtc('COMMENT',width=max_cmt_len),
|
||||
amt='{:{w}}'.format('BALANCE',w=max_fp_len+4),
|
||||
age=('CONFS','AGE')[show_days],
|
||||
cmt=TwComment.fmtc('COMMENT',width=max_cmt_len+1),
|
||||
amt='BALANCE'.ljust(max_fp_len+4),
|
||||
age=('CONFS','DAYS')[show_days],
|
||||
)]
|
||||
|
||||
def sort_algo(j):
|
||||
|
|
@ -763,7 +763,7 @@ def Listaddresses(addrs='',minconf=1,
|
|||
mid=MMGenID.fmtc(mmid_disp,width=max_mmid_len,color=True),
|
||||
addr=(e['addr'].fmt(color=True) if showbtcaddrs else None),
|
||||
cmt=e['lbl'].comment.fmt(width=max_cmt_len,color=True,nullrepl='-'),
|
||||
amt=e['amt'].fmt('3.{}'.format(max_fp_len),color=True),
|
||||
amt=e['amt'].fmt('4.{}'.format(max(max_fp_len,3)),color=True),
|
||||
age=mmid.confs / (1,confs_per_day)[show_days] if hasattr(mmid,'confs') else '-'
|
||||
))
|
||||
out.append('\nTOTAL: {} {}'.format(total.hl(color=True),g.coin))
|
||||
|
|
|
|||
47
mmgen/tw.py
47
mmgen/tw.py
|
|
@ -138,17 +138,16 @@ watch-only wallet using '{}-addrimport' and then re-run this program.
|
|||
# unsp.pdie()
|
||||
self.set_term_columns()
|
||||
|
||||
# Field widths
|
||||
min_mmid_w = 12 # DEADBEEF:S:1
|
||||
mmid_w = max(len(('',i.twmmid)[i.twmmid.type=='mmgen']) for i in unsp) or min_mmid_w
|
||||
# allow for 7-digit confirmation nums
|
||||
col1_w = max(3,len(str(len(unsp)))+1) # num + ')'
|
||||
mmid_w = max(len(('',i.twmmid)[i.twmmid.type=='mmgen']) for i in unsp) or 12 # DEADBEEF:S:1
|
||||
max_acct_w = max(len(i.label) for i in unsp) + mmid_w + 1
|
||||
addr_w = min(35+(0,1+max_acct_w)[self.show_mmid],self.cols-45)
|
||||
addr_w = min(g.proto.addr_width+(0,1+max_acct_w)[self.show_mmid],self.cols-45)
|
||||
acct_w = min(max_acct_w, max(24,int(addr_w-10)))
|
||||
btaddr_w = addr_w - acct_w - 1
|
||||
label_w = acct_w - mmid_w - 1
|
||||
tx_w = max(11,min(64, self.cols-addr_w-32))
|
||||
tx_w = max(11,min(64, self.cols-addr_w-28-col1_w))
|
||||
txdots = ('','...')[tx_w < 64]
|
||||
fs = ' %-4s %-{}s %-2s %s %s %s'.format(tx_w)
|
||||
|
||||
for i in unsp: i.skip = None
|
||||
if self.group and (self.sort_key in ('addr','txid','twmmid')):
|
||||
|
|
@ -161,9 +160,12 @@ watch-only wallet using '{}-addrimport' and then re-run this program.
|
|||
out = [hdr_fmt.format(' '.join(self.sort_info()),g.coin,self.total.hl())]
|
||||
if g.chain in ('testnet','regtest'):
|
||||
out += [green('Chain: {}'.format(g.chain.upper()))]
|
||||
af = CoinAddr.fmtc('Address',width=addr_w+1)
|
||||
cf = ('Conf.','Age(d)')[self.show_days]
|
||||
out += [fs % ('Num','TX id'.ljust(tx_w - 5) + ' Vout','',af,'Amt({}) '.format(g.coin),cf)]
|
||||
fs = ' {:%s} {:%s} {:2} {} {} {:<}' % (col1_w,tx_w)
|
||||
out += [fs.format('Num',
|
||||
'TX id'.ljust(tx_w - 5) + ' Vout', '',
|
||||
'Address'.ljust(addr_w+3),
|
||||
'Amt({})'.format(g.coin).ljust(10),
|
||||
('Confs','Age(d)')[self.show_days])]
|
||||
|
||||
for n,i in enumerate(unsp):
|
||||
addr_dots = '|' + '.'*33
|
||||
|
|
@ -184,7 +186,7 @@ watch-only wallet using '{}-addrimport' and then re-run this program.
|
|||
tx = ' ' * (tx_w-4) + '|...' if i.skip == 'txid' \
|
||||
else i.txid[:tx_w-len(txdots)]+txdots
|
||||
|
||||
out.append(fs % (str(n+1)+')',tx,i.vout,addr_out,i.amt.fmt(color=True),
|
||||
out.append(fs.format(str(n+1)+')',tx,i.vout,addr_out,i.amt.fmt(color=True),
|
||||
i.days if self.show_days else i.confs))
|
||||
|
||||
self.fmt_display = '\n'.join(out) + '\n'
|
||||
|
|
@ -193,21 +195,28 @@ watch-only wallet using '{}-addrimport' and then re-run this program.
|
|||
|
||||
def format_for_printing(self,color=False):
|
||||
|
||||
fs = ' %-4s %-67s %s %s %s %-8s %-6s %s'
|
||||
out = [fs % ('Num','Tx ID,Vout','Address'.ljust(34),'MMGen ID'.ljust(15),
|
||||
'Amount({})'.format(g.coin),'Conf.','Age(d)', 'Label')]
|
||||
mmid_w = max(len(('',i.twmmid)[i.twmmid.type=='mmgen']) for i in self.unspent) or 12 # DEADBEEF:S:1
|
||||
fs = ' {:4} {:67} {} {} {:12} {:<8} {:<6} {}'
|
||||
out = [fs.format('Num','Tx ID,Vout',
|
||||
'Address'.ljust(g.proto.addr_width),
|
||||
'MMGen ID'.ljust(mmid_w+1),
|
||||
'Amount({})'.format(g.coin),
|
||||
'Confs','Age(d)',
|
||||
'Label')]
|
||||
|
||||
max_lbl_len = max([len(i.label) for i in self.unspent if i.label] or [1])
|
||||
for n,i in enumerate(self.unspent):
|
||||
addr = '|'+'.' * 34 if i.skip == 'addr' and self.group else i.addr.fmt(color=color)
|
||||
addr = '|'+'.' * g.proto.addr_width if i.skip == 'addr' and self.group else i.addr.fmt(color=color)
|
||||
tx = '|'+'.' * 63 if i.skip == 'txid' and self.group else str(i.txid)
|
||||
s = fs % (str(n+1)+')', tx+','+str(i.vout),addr,
|
||||
out.append(
|
||||
fs.format(str(n+1)+')', tx+','+str(i.vout),
|
||||
addr,
|
||||
MMGenID.fmtc(i.twmmid if i.twmmid.type=='mmgen'
|
||||
else 'Non-{}'.format(g.proj_name),width=14,color=color),
|
||||
i.amt.fmt(color=color),i.confs,i.days,
|
||||
else 'Non-{}'.format(g.proj_name),width=mmid_w,color=color),
|
||||
i.amt.fmt(color=color),
|
||||
i.confs,i.days,
|
||||
i.label.hl(color=color) if i.label else
|
||||
TwComment.fmtc('',color=color,nullrepl='-',width=max_lbl_len))
|
||||
out.append(s.rstrip())
|
||||
TwComment.fmtc('',color=color,nullrepl='-',width=max_lbl_len)).rstrip())
|
||||
|
||||
fs = 'Unspent outputs ({} UTC)\nSort order: {}\n\n{}\n\nTotal {}: {}\n'
|
||||
self.fmt_print = fs.format(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue