From e7a60184ed887da9fcadd6e9399850a5762b2d44 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 16 Nov 2022 17:56:03 +0000 Subject: [PATCH] tw.view: skip rstrip() for screen formatting --- mmgen/tw/addresses.py | 5 ++--- mmgen/tw/txhistory.py | 4 ++-- mmgen/tw/unspent.py | 5 ++--- mmgen/tw/view.py | 17 ++++++++++++----- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/mmgen/tw/addresses.py b/mmgen/tw/addresses.py index a1515ca3..99afbfed 100755 --- a/mmgen/tw/addresses.py +++ b/mmgen/tw/addresses.py @@ -193,7 +193,7 @@ class TwAddresses(TwView): c = 'Comment', A = 'Balance', b = 'Block', - D = 'Date/Time' ).rstrip() + D = 'Date/Time' ) yes,no = (red('Yes '),green('No ')) if color else ('Yes ','No ') id_save = data[0].al_id @@ -210,8 +210,7 @@ class TwAddresses(TwView): c = d.comment.fmt( width=cw.comment, color=color, nullrepl='-' ), A = d.amt.fmt( color=color, iwidth=cw.iwidth, prec=self.disp_prec ), b = self.age_disp( d, 'block' ), - D = self.age_disp( d, 'date_time' ), - ).rstrip() + D = self.age_disp( d, 'date_time' )) async def set_dates(self,addrs): if not self.dates_set: diff --git a/mmgen/tw/txhistory.py b/mmgen/tw/txhistory.py index a21ee0d5..da745006 100755 --- a/mmgen/tw/txhistory.py +++ b/mmgen/tw/txhistory.py @@ -107,7 +107,7 @@ class TwTxHistory(TwView): i = 'Inputs', A = 'Amt({})'.format('TX' if self.show_total_amt else 'Wallet'), o = 'Outputs', - c = 'Comment' ).rstrip() + c = 'Comment' ) for n,d in enumerate(data,1): yield fs.format( @@ -117,7 +117,7 @@ class TwTxHistory(TwView): i = d.vouts_disp( 'inputs', width=cw.inputs, color=color ), A = d.amt_disp(self.show_total_amt).fmt( iwidth=cw.iwidth, prec=self.disp_prec, color=color ), o = d.vouts_disp( 'outputs', width=cw.outputs, color=color ), - c = d.comment.fmt( width=cw.comment, color=color, nullrepl='-' ) ).rstrip() + c = d.comment.fmt( width=cw.comment, color=color, nullrepl='-' ) ) def gen_detail_display(self,data,cw,hdr_fs,fs,color): diff --git a/mmgen/tw/unspent.py b/mmgen/tw/unspent.py index d01a7905..d8d45260 100755 --- a/mmgen/tw/unspent.py +++ b/mmgen/tw/unspent.py @@ -194,7 +194,7 @@ class TwUnspentOutputs(TwView): B = 'Amt({})'.format(self.proto.coin), b = 'Block', D = 'Date/Time', - c = 'Comment' ).rstrip() + c = 'Comment' ) for n,d in enumerate(data): yield fs.format( @@ -207,8 +207,7 @@ class TwUnspentOutputs(TwView): B = d.amt2.fmt( color=color, iwidth=cw.iwidth2, prec=self.disp_prec ) if cw.amt2 else None, b = self.age_disp(d,'block'), D = self.age_disp(d,'date_time'), - c = d.comment.fmt( width=cw.comment, color=color, nullrepl='-' ), - ).rstrip() + c = d.comment.fmt( width=cw.comment, color=color, nullrepl='-' )) def display_total(self): msg('\nTotal unspent: {} {} ({} output{})'.format( diff --git a/mmgen/tw/view.py b/mmgen/tw/view.py index 214eb263..bf5ab579 100755 --- a/mmgen/tw/view.py +++ b/mmgen/tw/view.py @@ -317,7 +317,7 @@ class TwView(MMGenObject,metaclass=AsyncInit): min(7,max(len(str(getattr(d,k).to_integral_value())) for d in data)) + 1 + self.disp_prec for k in self.amt_keys} - async def format(self,display_type,color=True,cached=False,interactive=False): + async def format(self,display_type,color=True,cached=False,interactive=False,for_printing=False): if not cached: @@ -342,11 +342,18 @@ class TwView(MMGenObject,metaclass=AsyncInit): else: cw = hdr_fs = fs = None + if for_printing: + color = False + self._display_data[display_type] = '{a}{b}\n{c}\n'.format( a = self.header(color), b = self.subheader(color), - c = dt.item_separator.join(getattr(self,dt.fmt_method)(data,cw,hdr_fs,fs,color=color)) - if data else (nocolor,yellow)[color]('[no data for requested parameters]') + c = ( + dt.item_separator.join( + (l.rstrip() for l in getattr(self,dt.fmt_method)(data,cw,hdr_fs,fs,color=color))) + if for_printing else + dt.item_separator.join(getattr(self,dt.fmt_method)(data,cw,hdr_fs,fs,color=color)) + ) if data else (nocolor,yellow)[color]('[no data for requested parameters]') ) return self._display_data[display_type] + ('' if interactive else self.footer(color)) @@ -430,11 +437,11 @@ class TwView(MMGenObject,metaclass=AsyncInit): msg('') from ..fileutil import write_data_to_file from ..exception import UserNonConfirmation - hdr = getattr(parent.display_type,output_type).print_header.format(parent.cols) + print_hdr = getattr(parent.display_type,output_type).print_header.format(parent.cols) try: write_data_to_file( outfile = outfile, - data = hdr + await parent.format(display_type=output_type,color=False), + data = print_hdr + await parent.format(display_type=output_type,for_printing=True), desc = f'{parent.desc} listing' ) except UserNonConfirmation as e: parent.oneshot_msg = yellow(f'File {outfile!r} not overwritten by user request\n\n')