proto.eth.tw.unspent: implement get_column_widths() in parent cls

This commit is contained in:
The MMGen Project 2025-05-26 09:39:11 +00:00
commit 3aed085021
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
5 changed files with 39 additions and 44 deletions

View file

@ -43,6 +43,8 @@ class BitcoinTwUnspentOutputs(BitcoinTwView, TwUnspentOutputs):
has_age = True
can_group = True
disp_spc = 5
vout_w = 4
hdr_lbl = 'unspent outputs'
desc = 'unspent outputs'
item_desc = 'unspent output'

View file

@ -13,4 +13,17 @@ proto.btc.tw.view: Bitcoin base protocol base class for tracking wallet view cla
"""
class BitcoinTwView:
pass
txid_w = 64
txid_max_w = {'txid': 64}
txid_min_w = {'txid': 7}
txid_nice_w = {'txid': 12}
nice_addr_w = {'addr': 16}
age_col_params = {
'confs': (7, 'Confs'),
'block': (8, 'Block'),
'days': (6, 'Age(d)'),
'date': (8, 'Date'),
'date_time': (16, 'Date/Time'),
}

View file

@ -36,35 +36,6 @@ class EthereumTwUnspentOutputs(EthereumTwView, TwUnspentOutputs):
item_desc = 'account'
item_desc_pl = 'accounts'
def get_column_widths(self, data, *, wide, interactive):
# min screen width: 80 cols
# num addr [mmid] [comment] amt [amt2]
return self.compute_column_widths(
widths = { # fixed cols
'num': max(2, len(str(len(data)))+1),
'mmid': max(len(d.twmmid.disp) for d in data) if self.show_mmid else 0,
'amt': self.amt_widths['amt'],
'amt2': self.amt_widths.get('amt2', 0),
'spc': (5 if self.show_mmid else 3) + self.has_amt2, # 5(3) spaces in fs
'txid': 0,
'vout': 0,
'block': 0,
'date': 0,
'date_time': 0,
},
maxws = { # expandable cols
'addr': max(len(d.addr) for d in data),
'comment': max(d.comment.screen_width for d in data) if self.show_mmid else 0,
},
minws = {
'addr': 10,
'comment': len('Comment') if self.show_mmid else 0,
},
maxws_nice = {'addr': 14} if self.show_mmid else {},
wide = wide,
interactive = interactive,
)
def do_sort(self, key=None, *, reverse=False):
if key == 'txid':
return

View file

@ -39,6 +39,9 @@ class TwUnspentOutputs(TwView):
has_age = False
can_group = False
show_mmid = True
hdr_lbl = 'tracked addresses'
desc = 'address balances'
item_desc = 'address'
item_desc_pl = 'addresses'
no_rpcdata_errmsg = """
No spendable outputs found! Import addresses with balances into your
@ -67,6 +70,8 @@ class TwUnspentOutputs(TwView):
extra_key_mappings = {
'D':'i_addr_delete',
'R':'i_balance_refresh'}
disp_spc = 3
vout_w = 0
class display_type(TwView.display_type):
@ -142,30 +147,30 @@ class TwUnspentOutputs(TwView):
show_mmid = self.show_mmid or wide
# num txid vout addr [mmid] [comment] amt [amt2] date
return self.compute_column_widths(
widths = { # fixed cols
'num': max(2, len(str(len(data)))+1),
'vout': 4,
'txid': 0,
'vout': self.vout_w,
'mmid': max(len(d.twmmid.disp) for d in data) if show_mmid else 0,
'amt': self.amt_widths['amt'],
'amt2': self.amt_widths.get('amt2', 0),
'block': self.age_col_params['block'][0] if wide else 0,
'date_time': self.age_col_params['date_time'][0] if wide else 0,
'date': self.age_w,
'spc': 7 if show_mmid else 5, # 7(5) spaces in fs
'spc': self.disp_spc + (2 * show_mmid) + self.has_amt2
},
maxws = { # expandable cols
'txid': self.txid_w,
'addr': max(len(d.addr) for d in data),
'comment': max(d.comment.screen_width for d in data) if show_mmid else 0,
},
} | self.txid_max_w,
minws = {
'txid': 7,
'addr': 10,
'comment': len('Comment') if show_mmid else 0,
},
maxws_nice = {'txid':12, 'addr':16} if show_mmid else {'txid':12},
} | self.txid_min_w,
maxws_nice = (
self.nice_addr_w if show_mmid else {}
) | self.txid_nice_w,
wide = wide,
interactive = interactive,
)

View file

@ -87,7 +87,11 @@ class TwView(MMGenObject, metaclass=AsyncInit):
group = False
use_cached = False
minconf = 1
txid_w = 64
txid_w = 0
txid_max_w = {}
txid_min_w = {}
txid_nice_w = {}
nice_addr_w = {'addr': 14}
sort_key = 'age'
display_hdr = ()
display_body = ()
@ -127,11 +131,11 @@ class TwView(MMGenObject, metaclass=AsyncInit):
bch_addr_fmts = ('cashaddr', 'legacy')
age_col_params = {
'confs': (7, 'Confs'),
'block': (8, 'Block'),
'days': (6, 'Age(d)'),
'date': (8, 'Date'),
'date_time': (16, 'Date/Time'),
'confs': (0, 'Confs'),
'block': (0, 'Block'),
'days': (0, 'Age(d)'),
'date': (0, 'Date'),
'date_time': (0, 'Date/Time'),
}
date_formatter = {