tw.addresses: improve line filtering logic

This commit is contained in:
The MMGen Project 2025-11-29 09:12:48 +00:00
commit 9c13bdd1f1
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
3 changed files with 23 additions and 10 deletions

View file

@ -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"

View file

@ -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):

View file

@ -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(),