From 270fee37852d578bcc2413081b2593eac1368563 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sun, 11 Dec 2022 12:12:07 +0000 Subject: [PATCH] tw.unspent: wide display fix; tw.view: minor cleanups --- mmgen/tw/unspent.py | 18 ++++++++---------- mmgen/tw/view.py | 23 ++++++++++------------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/mmgen/tw/unspent.py b/mmgen/tw/unspent.py index 4818808e..6db3beab 100755 --- a/mmgen/tw/unspent.py +++ b/mmgen/tw/unspent.py @@ -121,35 +121,33 @@ class TwUnspentOutputs(TwView): return data def get_column_widths(self,data,wide,interactive): - # min screen width: 80 cols - # num txid vout addr [mmid] [comment] amt [amt2] date - maxws_nice = {'txid': 12} - if self.show_mmid: - maxws_nice['addr'] = 16 + 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, - 'mmid': max(len(d.twmmid.disp) for d in data) if self.show_mmid else 0, + '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 self.show_mmid else 5, # 7(5) spaces in fs + 'spc': 7 if show_mmid else 5, # 7(5) spaces in fs }, 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 self.show_mmid else 0, + 'comment': max(d.comment.screen_width for d in data) if show_mmid else 0, }, minws = { 'txid': 7, 'addr': 10, - 'comment': len('Comment') if self.show_mmid else 0, + 'comment': len('Comment') if show_mmid else 0, }, - maxws_nice = maxws_nice, + maxws_nice = {'txid':12, 'addr':16} if show_mmid else {'txid':12}, wide = wide, interactive = interactive, ) diff --git a/mmgen/tw/view.py b/mmgen/tw/view.py index a1d899b9..82396f9f 100755 --- a/mmgen/tw/view.py +++ b/mmgen/tw/view.py @@ -495,26 +495,23 @@ class TwView(MMGenObject,metaclass=AsyncInit): async def view_filter_and_sort(self): - def make_prompt(scroll): + def make_key_mappings(scroll): if scroll: for k in self.scroll_keys['vi']: assert k not in self.key_mappings, f'{k!r} is in key_mappings' self.key_mappings.update(self.scroll_keys['vi']) self.key_mappings.update(self.scroll_keys[g.platform]) - s = '\nScrolling: k=up, j=down, b=pgup, f=pgdown, g=top, G=bottom' - else: - s = '' - return self.prompt_fs.strip().format(s=s) - - from ..term import get_term,get_char,get_char_raw + return self.key_mappings scroll = self.scroll = g.scroll - prompt = make_prompt(scroll) + key_mappings = make_key_mappings(scroll) + prompt = self.prompt_fs.strip().format( + s='\nScrolling: k=up, j=down, b=pgup, f=pgdown, g=top, G=bottom' if scroll else '' ) self.prompt_width = max(len(l) for l in prompt.split('\n')) self.prompt_height = len(prompt.split('\n')) - self.oneshot_msg = None + self.oneshot_msg = '' prompt += '\b' clear_screen = '\n\n' if opt.no_blank else CUR_HOME + ('' if scroll else ERASE_ALL) @@ -539,17 +536,17 @@ class TwView(MMGenObject,metaclass=AsyncInit): + '\n\n' + (self.oneshot_msg + '\n\n' if self.oneshot_msg and not scroll else '') + prompt, - immed_chars = self.key_mappings ) + immed_chars = key_mappings ) - self.oneshot_msg = '' if self.oneshot_msg else None # tristate, saves previous state + self.oneshot_msg = '' - if reply not in self.key_mappings: + if reply not in key_mappings: if not scroll: msg_r('\ninvalid keypress ') await asyncio.sleep(0.3) continue - action = self.key_mappings[reply] + action = key_mappings[reply] if scroll and action.startswith('a_'): # 'a_' actions may require line input term.set('echo')