From 65c0652ff523bece46220a261b91bd6fd95335b4 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 7 Dec 2022 10:40:57 +0000 Subject: [PATCH] tw.view: improve gen_subheader(), col_hdr implementation --- mmgen/proto/eth/tw/view.py | 2 +- mmgen/tw/addresses.py | 2 +- mmgen/tw/txhistory.py | 55 +++++++++++++++++--------------------- mmgen/tw/view.py | 14 ++++++---- 4 files changed, 36 insertions(+), 37 deletions(-) diff --git a/mmgen/proto/eth/tw/view.py b/mmgen/proto/eth/tw/view.py index ee1c6ff3..ea63c84d 100755 --- a/mmgen/proto/eth/tw/view.py +++ b/mmgen/proto/eth/tw/view.py @@ -23,7 +23,7 @@ class EthereumTwView(TwView): def get_disp_prec(self,wide): return self.proto.coin_amt.max_prec if wide else 8 - def gen_subheader(self,color): + def gen_subheader(self,cw,color): if self.disp_prec == 8: yield 'Balances truncated to 8 decimal points' if g.cached_balances: diff --git a/mmgen/tw/addresses.py b/mmgen/tw/addresses.py index fe3c589c..ce3759d0 100755 --- a/mmgen/tw/addresses.py +++ b/mmgen/tw/addresses.py @@ -151,7 +151,7 @@ class TwAddresses(TwView): wide = wide, ) - def gen_subheader(self,color): + def gen_subheader(self,cw,color): if self.minconf: yield f'Displaying balances with at least {self.minconf} confirmation{suf(self.minconf)}' diff --git a/mmgen/tw/txhistory.py b/mmgen/tw/txhistory.py index 354e7057..30778185 100755 --- a/mmgen/tw/txhistory.py +++ b/mmgen/tw/txhistory.py @@ -25,11 +25,11 @@ class TwTxHistory(TwView): class squeezed(TwView.display_type.squeezed): cols = ('num','txid','date','inputs','amt','outputs','comment') - hdr_fmt_method = 'squeezed_hdr' + subhdr_fmt_method = 'gen_squeezed_subheader' class detail(TwView.display_type.detail): need_column_widths = False - hdr_fmt_method = 'detail_hdr' + subhdr_fmt_method = 'gen_detail_subheader' item_separator = '\n\n' has_wallet = False @@ -91,37 +91,32 @@ class TwTxHistory(TwView): return self.compute_column_widths(widths,maxws,minws,maxws_nice,wide=wide) - def squeezed_hdr(self,cw,fs,color): + def gen_squeezed_subheader(self,cw,color): + 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' - def gen(): - 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 '' + def gen_detail_subheader(self,cw,color): + if self.sinceblock: + yield f'Displaying transactions since block {self.sinceblock.hl(color=color)}' + yield 'Only wallet-related outputs are shown' - yield fs.format( - n = '', - t = 'TxID', - d = self.age_hdr, - i = 'Inputs', - A = 'Amt({})'.format('TX' if self.show_total_amt else 'Wallet'), - o = 'Outputs', - c = 'Comment' ) + def squeezed_col_hdr(self,cw,fs,color): + return fs.format( + n = '', + t = 'TxID', + d = self.age_hdr, + i = 'Inputs', + A = 'Amt({})'.format('TX' if self.show_total_amt else 'Wallet'), + o = 'Outputs', + c = 'Comment' ) - return '\n'.join(gen()) - - def detail_hdr(self,cw,fs,color): - - def gen(): - if self.sinceblock: - yield f'Displaying transactions since block {self.sinceblock.hl(color=color)}' - yield 'Only wallet-related outputs are shown' - - return '\n'.join(gen()) + '\n\n' + def detail_col_hdr(self,cw,fs,color): + return '' def gen_squeezed_display(self,data,cw,fs,color,fmt_method): diff --git a/mmgen/tw/view.py b/mmgen/tw/view.py index 6773b4e8..424a03ae 100755 --- a/mmgen/tw/view.py +++ b/mmgen/tw/view.py @@ -45,7 +45,8 @@ class TwView(MMGenObject,metaclass=AsyncInit): detail = False fmt_method = 'gen_squeezed_display' line_fmt_method = 'squeezed_format_line' - hdr_fmt_method = 'squeezed_col_hdr' + subhdr_fmt_method = 'gen_subheader' + colhdr_fmt_method = 'squeezed_col_hdr' need_column_widths = True item_separator = '\n' print_header = '[screen print truncated to width {}]\n' @@ -54,7 +55,8 @@ class TwView(MMGenObject,metaclass=AsyncInit): detail = True fmt_method = 'gen_detail_display' line_fmt_method = 'detail_format_line' - hdr_fmt_method = 'detail_col_hdr' + subhdr_fmt_method = 'gen_subheader' + colhdr_fmt_method = 'detail_col_hdr' need_column_widths = True item_separator = '\n' print_header = '' @@ -302,7 +304,7 @@ class TwView(MMGenObject,metaclass=AsyncInit): else: return do_ret(get_freews(self.cols,varws,varw,minw)) - def gen_subheader(self,color): + def gen_subheader(self,cw,color): return () def gen_footer(self,color): @@ -348,12 +350,14 @@ class TwView(MMGenObject,metaclass=AsyncInit): if hasattr(self,'total'): yield 'Total {}: {}'.format( self.proto.dcoin, self.total.hl(color=color) ) - yield from self.gen_subheader(color) + yield from getattr(self,dt.subhdr_fmt_method)(cw,color) yield '' if data: - yield getattr(self,dt.hdr_fmt_method)(cw,hdr_fs,color) + res = getattr(self,dt.colhdr_fmt_method)(cw,hdr_fs,color) + if res: + yield res self.disp_prec = self.get_disp_prec(wide=dt.detail)