tw.view: new column_widths_data attribute

This commit is contained in:
The MMGen Project 2025-11-30 12:22:37 +00:00
commit de1a71a5f1
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
6 changed files with 30 additions and 51 deletions

View file

@ -1 +1 @@
16.1.dev18
16.1.dev19

View file

@ -163,8 +163,8 @@ class MoneroTwView:
fmt_method = 'gen_display'
line_fmt_method = 'squeezed_format_line'
def get_column_widths(self, data, *, wide, interactive):
return self.compute_column_widths(
def get_column_widths(self, data, *, wide):
return self.column_widths_data(
widths = { # fixed cols
'addr_idx': MoneroIdx.max_digits,
'used': 4 if 'used' in self.display_type.squeezed.cols else 0,
@ -176,9 +176,7 @@ class MoneroTwView:
minws = {
'addr': 16,
'comment': len('Comment')},
maxws_nice = self.nice_addr_w,
wide = wide,
interactive = interactive)
maxws_nice = self.nice_addr_w)
def gen_display(self, data, cw, fs, color, fmt_method):
yes, no = (red('Used'), green('New ')) if color else ('Used', 'New ')

View file

@ -186,9 +186,8 @@ class TwAddresses(TwView):
if d.is_used:
yield d
def get_column_widths(self, data, *, wide, interactive):
return self.compute_column_widths(
def get_column_widths(self, data, *, wide):
return self.column_widths_data(
widths = { # fixed cols
'num': max(2, len(str(len(data)))+1),
'mmid': max(len(d.twmmid.disp) for d in data),
@ -204,9 +203,7 @@ class TwAddresses(TwView):
minws = {
'addr': 12 if self.showcoinaddrs else 0,
'comment': len('Comment')},
maxws_nice = {'addr': 18},
wide = wide,
interactive = interactive)
maxws_nice = {'addr': 18})
def squeezed_col_hdr(self, cw, fs, color):
return fs.format(

View file

@ -58,8 +58,7 @@ class TwTxHistory(TwView):
amts_tuple = namedtuple('amts_data', ['amt'])
return super().set_amt_widths([amts_tuple(d.amt_disp(self.show_total_amt)) for d in data])
def get_column_widths(self, data, *, wide, interactive):
def get_column_widths(self, data, *, wide):
# var cols: inputs outputs comment [txid]
if not hasattr(self, 'varcol_maxwidths'):
self.varcol_maxwidths = {
@ -71,34 +70,18 @@ class TwTxHistory(TwView):
for d in data),
'comment': max(len(d.comment)
for d in data)}
maxws = self.varcol_maxwidths.copy()
minws = {
'inputs': 15,
'outputs': 15,
'comment': len('Comment')}
if self.show_txid:
maxws['txid'] = self.txid_w
minws['txid'] = 8
maxws_nice = {'txid': 20}
else:
maxws['txid'] = 0
minws['txid'] = 0
maxws_nice = {}
widths = { # fixed cols
'num': max(2, len(str(len(data)))+1),
'date': self.age_w,
'amt': self.amt_widths['amt'],
'spc': 6 + self.show_txid} # 5(6) spaces between cols + 1 leading space in fs
return self.compute_column_widths(
widths,
maxws,
minws,
maxws_nice,
wide = wide,
interactive = interactive)
return self.column_widths_data(
widths = { # fixed cols
'num': max(2, len(str(len(data)))+1),
'date': self.age_w,
'amt': self.amt_widths['amt'],
'spc': 6 + self.show_txid}, # 5(6) spaces between cols + 1 leading space in fs
maxws = self.varcol_maxwidths | {'txid': self.txid_w if self.show_txid else 0},
minws = {
'inputs': 15,
'outputs': 15,
'comment': len('Comment')} | {'txid': 8 if self.show_txid else 0},
maxws_nice = {'txid': 20 if self.show_txid else 0})
def gen_squeezed_subheader(self, cw, color):
# keep these shorter than min screen width (currently prompt width, or 65 chars)

View file

@ -151,11 +151,9 @@ class TwUnspentOutputs(TwView):
return self.data
def get_column_widths(self, data, *, wide, interactive):
def get_column_widths(self, data, *, wide):
show_mmid = self.show_mmid or wide
return self.compute_column_widths(
return self.column_widths_data(
widths = { # fixed cols
'num': max(2, len(str(len(data)))+1),
'txid': 0,
@ -177,9 +175,7 @@ class TwUnspentOutputs(TwView):
} | self.txid_min_w,
maxws_nice = (
self.nice_addr_w if show_mmid else {}
) | self.txid_nice_w,
wide = wide,
interactive = interactive)
) | self.txid_nice_w)
def squeezed_col_hdr(self, cw, fs, color):
return fs.format(

View file

@ -110,6 +110,7 @@ class TwView(MMGenObject, metaclass=AsyncInit):
pos = 0
filters = ()
column_widths_data = namedtuple('twview_column_widths', ['widths', 'maxws', 'minws', 'maxws_nice'])
fp = namedtuple('fs_params', ['fs_key', 'hdr_fs_repl', 'fs_repl', 'hdr_fs', 'fs'])
fs_params = {
'num': fp('n', True, True, ' {n:>%s}', ' {n:>%s}'),
@ -328,7 +329,7 @@ class TwView(MMGenObject, metaclass=AsyncInit):
else:
return _term_dimensions(min_cols, ts.height)
def compute_column_widths(self, widths, maxws, minws, maxws_nice, *, wide, interactive):
def compute_column_widths(self, in_data, *, wide, interactive):
def do_ret(freews):
if freews:
@ -356,6 +357,7 @@ class TwView(MMGenObject, metaclass=AsyncInit):
else:
return {k:0 for k in varws}
widths, maxws, minws, maxws_nice = in_data
varws = {k: maxws[k] - minws[k] for k in maxws if maxws[k] > minws[k]}
minw = sum(widths.values()) + sum(minws.values())
varw = sum(varws.values())
@ -487,7 +489,10 @@ class TwView(MMGenObject, metaclass=AsyncInit):
if self.disp_data and dt.need_column_widths:
self.set_amt_widths(self.disp_data)
cw = self.get_column_widths(self.disp_data, wide=dt.detail, interactive=interactive)
cw = self.compute_column_widths(
self.get_column_widths(self.disp_data, wide=dt.detail),
wide = dt.detail,
interactive = interactive)
cwh = cw._asdict()
fp = self.fs_params
rfill = ' ' * (self.term_width - self.cols) if scroll else ''