From de1a71a5f11d76237903594a9d1423c08a8b2ffa Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sun, 30 Nov 2025 12:22:37 +0000 Subject: [PATCH] tw.view: new `column_widths_data` attribute --- mmgen/data/version | 2 +- mmgen/proto/xmr/tw/view.py | 8 +++---- mmgen/tw/addresses.py | 9 +++----- mmgen/tw/txhistory.py | 43 ++++++++++++-------------------------- mmgen/tw/unspent.py | 10 +++------ mmgen/tw/view.py | 9 ++++++-- 6 files changed, 30 insertions(+), 51 deletions(-) diff --git a/mmgen/data/version b/mmgen/data/version index 918bc138..6471f962 100644 --- a/mmgen/data/version +++ b/mmgen/data/version @@ -1 +1 @@ -16.1.dev18 +16.1.dev19 diff --git a/mmgen/proto/xmr/tw/view.py b/mmgen/proto/xmr/tw/view.py index b1877b1e..2a8cb7b6 100755 --- a/mmgen/proto/xmr/tw/view.py +++ b/mmgen/proto/xmr/tw/view.py @@ -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 ') diff --git a/mmgen/tw/addresses.py b/mmgen/tw/addresses.py index ced8738e..50ffa5a8 100755 --- a/mmgen/tw/addresses.py +++ b/mmgen/tw/addresses.py @@ -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( diff --git a/mmgen/tw/txhistory.py b/mmgen/tw/txhistory.py index 51d388c5..57a889e2 100755 --- a/mmgen/tw/txhistory.py +++ b/mmgen/tw/txhistory.py @@ -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) diff --git a/mmgen/tw/unspent.py b/mmgen/tw/unspent.py index 7dbe3e3d..74667121 100755 --- a/mmgen/tw/unspent.py +++ b/mmgen/tw/unspent.py @@ -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( diff --git a/mmgen/tw/view.py b/mmgen/tw/view.py index fe25ab9c..b0af8b9a 100755 --- a/mmgen/tw/view.py +++ b/mmgen/tw/view.py @@ -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 ''