From 60d0a29c364be17dda96594d05178bd0fe6780cf Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 7 Dec 2022 10:40:57 +0000 Subject: [PATCH] tw.view: ensure min screen width >= prompt width --- mmgen/proto/eth/tw/addresses.py | 3 ++- mmgen/proto/eth/tw/unspent.py | 3 ++- mmgen/tw/addresses.py | 3 ++- mmgen/tw/txhistory.py | 7 ++++--- mmgen/tw/unspent.py | 3 ++- mmgen/tw/view.py | 11 +++++++---- 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/mmgen/proto/eth/tw/addresses.py b/mmgen/proto/eth/tw/addresses.py index 7b79006d..f30af468 100755 --- a/mmgen/proto/eth/tw/addresses.py +++ b/mmgen/proto/eth/tw/addresses.py @@ -41,7 +41,7 @@ Actions: [q]uit, r[e]draw, [D]elete address, add [l]abel: 'w':'a_view_detail', 'p':'a_print_detail' } - def get_column_widths(self,data,wide=False): + def get_column_widths(self,data,wide,interactive): return self.compute_column_widths( widths = { # fixed cols @@ -64,6 +64,7 @@ Actions: [q]uit, r[e]draw, [D]elete address, add [l]abel: }, maxws_nice = {'addr': 18}, wide = wide, + interactive = interactive, ) async def get_rpc_data(self): diff --git a/mmgen/proto/eth/tw/unspent.py b/mmgen/proto/eth/tw/unspent.py index e17a7053..da0733fe 100755 --- a/mmgen/proto/eth/tw/unspent.py +++ b/mmgen/proto/eth/tw/unspent.py @@ -68,7 +68,7 @@ Actions: [q]uit view, [p]rint to file, pager [v]iew, [w]ide view, no_data_errmsg = 'No accounts in tracking wallet!' - def get_column_widths(self,data,wide=False): + def get_column_widths(self,data,wide,interactive): # min screen width: 80 cols # num addr [mmid] [comment] amt [amt2] return self.compute_column_widths( @@ -94,6 +94,7 @@ Actions: [q]uit view, [p]rint to file, pager [v]iew, [w]ide view, }, maxws_nice = {'addr': 14} if self.show_mmid else {}, wide = wide, + interactive = interactive, ) def do_sort(self,key=None,reverse=False): diff --git a/mmgen/tw/addresses.py b/mmgen/tw/addresses.py index ce3759d0..5bb641e4 100755 --- a/mmgen/tw/addresses.py +++ b/mmgen/tw/addresses.py @@ -126,7 +126,7 @@ class TwAddresses(TwView): (not (d.recvd and not self.showused) and (d.amt or self.showempty)) ) - def get_column_widths(self,data,wide=False): + def get_column_widths(self,data,wide,interactive): return self.compute_column_widths( widths = { # fixed cols @@ -149,6 +149,7 @@ class TwAddresses(TwView): }, maxws_nice = {'addr': 18}, wide = wide, + interactive = interactive, ) def gen_subheader(self,cw,color): diff --git a/mmgen/tw/txhistory.py b/mmgen/tw/txhistory.py index 30778185..71af7b04 100755 --- a/mmgen/tw/txhistory.py +++ b/mmgen/tw/txhistory.py @@ -57,7 +57,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=False): + def get_column_widths(self,data,wide,interactive): # var cols: inputs outputs comment [txid] if not hasattr(self,'varcol_maxwidths'): @@ -89,16 +89,17 @@ class TwTxHistory(TwView): '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) + return self.compute_column_widths(widths,maxws,minws,maxws_nice,wide=wide,interactive=interactive) def gen_squeezed_subheader(self,cw,color): + # keep these shorter than min screen width (currently prompt width, or 65 chars) if self.sinceblock: yield f'Displaying transactions since block {self.sinceblock.hl(color=color)}' yield 'Only wallet-related outputs are shown' yield 'Comment is from first wallet address in outputs or inputs' if (cw.inputs < self.varcol_maxwidths['inputs'] or cw.outputs < self.varcol_maxwidths['outputs'] ): - yield 'Due to screen width limitations, not all addresses could be displayed' + yield 'Note: screen is too narrow to display all inputs and outputs' def gen_detail_subheader(self,cw,color): if self.sinceblock: diff --git a/mmgen/tw/unspent.py b/mmgen/tw/unspent.py index 121421d2..0f0b8808 100755 --- a/mmgen/tw/unspent.py +++ b/mmgen/tw/unspent.py @@ -120,7 +120,7 @@ class TwUnspentOutputs(TwView): return data - def get_column_widths(self,data,wide=False): + 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} @@ -151,6 +151,7 @@ class TwUnspentOutputs(TwView): }, maxws_nice = maxws_nice, wide = wide, + interactive = interactive, ) def squeezed_col_hdr(self,cw,fs,color): diff --git a/mmgen/tw/view.py b/mmgen/tw/view.py index 424a03ae..0fa0ca90 100755 --- a/mmgen/tw/view.py +++ b/mmgen/tw/view.py @@ -242,7 +242,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=False): + def compute_column_widths(self,widths,maxws,minws,maxws_nice,wide,interactive): def do_ret(freews): widths.update({k:minws[k] + freews.get(k,0) for k in minws}) @@ -274,7 +274,8 @@ class TwView(MMGenObject,metaclass=AsyncInit): minw = sum(widths.values()) + sum(minws.values()) varw = sum(varws.values()) - td = self.get_term_dimensions(minw) + self.min_term_width = max(self.prompt_width,minw) if interactive else minw + td = self.get_term_dimensions(self.min_term_width) self.term_height = td.height self.term_width = td.width @@ -368,7 +369,7 @@ class TwView(MMGenObject,metaclass=AsyncInit): if data and dt.need_column_widths: self.set_amt_widths(data) - cw = self.get_column_widths(data,wide=dt.detail) + cw = self.get_column_widths(data,wide=dt.detail,interactive=interactive) cwh = cw._asdict() fp = self.fs_params hdr_fs = ''.join(fp[name].hdr_fs % ((),cwh[name])[fp[name].hdr_fs_repl] @@ -421,11 +422,13 @@ class TwView(MMGenObject,metaclass=AsyncInit): from ..term import get_char - prompt = self.prompt.strip() + '\b' + prompt = self.prompt.strip() + self.prompt_width = max(len(l) for l in prompt.split('\n')) self.prompt_height = len(prompt.split('\n')) self.no_output = False self.oneshot_msg = None + prompt += '\b' self.cursor_to_end_of_prompt = CUR_RIGHT( len(prompt.split('\n')[-1]) - 2 ) clear_screen = '\n\n' if (opt.no_blank or g.test_suite) else CUR_HOME + ERASE_ALL