From 9c13bdd1f1a895dbb34a1a618be4b204618815e5 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sat, 29 Nov 2025 09:12:48 +0000 Subject: [PATCH] tw.addresses: improve line filtering logic --- mmgen/tool/rpc.py | 2 +- mmgen/tw/addresses.py | 25 +++++++++++++++++++------ mmgen/tw/view.py | 6 +++--- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/mmgen/tool/rpc.py b/mmgen/tool/rpc.py index 62c03daa..577cff2c 100755 --- a/mmgen/tool/rpc.py +++ b/mmgen/tool/rpc.py @@ -141,7 +141,7 @@ class tool_cmd(tool_cmd_base): mmgen_addrs: 'hyphenated range or comma-separated list of addresses' = '', showcoinaddrs:'display coin addresses in addition to MMGen IDs' = True, showempty: 'show addresses with no balances' = True, - showused: 'show used addresses (tristate: 0=no, 1=yes, 2=all)' = 1, + showused: 'show used addresses (tristate: 0=no, 1=yes, 2=only)' = 1, all_labels: 'show all addresses with labels' = False): "list MMGen addresses in the tracking wallet and their balances" diff --git a/mmgen/tw/addresses.py b/mmgen/tw/addresses.py index 48d56b9a..7b330065 100755 --- a/mmgen/tw/addresses.py +++ b/mmgen/tw/addresses.py @@ -32,7 +32,7 @@ class TwAddresses(TwView): filters = ('showempty', 'showused', 'all_labels') showcoinaddrs = True showempty = True - showused = 1 # tristate: 0: no, 1: yes, 2: all + showused = 1 # tristate: 0: no, 1: yes, 2: only all_labels = False mod_subpath = 'tw.addresses' has_age = False @@ -168,12 +168,25 @@ class TwAddresses(TwView): def get_disp_data(self): if self.usr_addr_list: - return (d for d in self.data if d.twmmid.obj in self.usr_addr_list) + for d in self.data: + if d.twmmid.obj in self.usr_addr_list: + yield d else: - return (d for d in self.data if - (self.all_labels and d.comment) or - (self.showused == 2 and d.is_used) or - (not (d.is_used and not self.showused) and (d.amt or self.showempty))) + for d in self.data: + if self.all_labels and d.comment: + yield d + else: + if not (self.showempty or d.amt): + continue + match self.showused: # tristate: 0:no, 1:yes, 2:only + case 0: + if not d.is_used: + yield d + case 1: + yield d + case 2: + if d.is_used: + yield d def get_column_widths(self, data, *, wide, interactive): diff --git a/mmgen/tw/view.py b/mmgen/tw/view.py index 50cbad40..7337e723 100755 --- a/mmgen/tw/view.py +++ b/mmgen/tw/view.py @@ -426,15 +426,15 @@ class TwView(MMGenObject, metaclass=AsyncInit): if color: Blue, Green = (blue, green) - Yes, No, All = (green('yes'), red('no'), yellow('all')) + Yes, No, Only = (green('yes'), red('no'), yellow('only')) else: Blue, Green = (nocolor, nocolor) - Yes, No, All = ('yes', 'no', 'all') + Yes, No, Only = ('yes', 'no', 'only') sort_info = ' '.join(self.sort_info()) def fmt_filter(k): - return '{}:{}'.format(k, {0: No, 1: Yes, 2: All}[getattr(self, k)]) + return '{}:{}'.format(k, {0: No, 1: Yes, 2: Only}[getattr(self, k)]) yield '{} (sort order: {}){}'.format( self.hdr_lbl.upper(),