From 0a15625e833c82b2508486b9854676ee9aa9e01b Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 25 Sep 2023 13:25:01 +0000 Subject: [PATCH] tw: remove trailing space when saving output to file --- mmgen/tw/bal.py | 6 +++--- mmgen/tw/json.py | 2 +- mmgen/tw/view.py | 8 ++++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/mmgen/tw/bal.py b/mmgen/tw/bal.py index 93ecc1aa..7810828f 100755 --- a/mmgen/tw/bal.py +++ b/mmgen/tw/bal.py @@ -91,7 +91,7 @@ class TwGetBalance(MMGenObject,metaclass=AsyncInit): lbl = 'Wallet', w = col1_w + iwidth_adj, cols = ' '.join(v.format(minconf=self.minconf).ljust(iwidths[k]+add_w) - for k,v in self.conf_cols.items()) ) + for k,v in self.conf_cols.items()) ).rstrip() from ..addr import MMGenID for label in sorted(self.data.keys()): @@ -99,7 +99,7 @@ class TwGetBalance(MMGenObject,metaclass=AsyncInit): lbl = yellow((label + ' ' + self.proto.coin).ljust(col1_w)) if label == 'TOTAL' else MMGenID.hlc( (label+':').ljust(col1_w), color=color ), cols = ' '.join(make_col(label,col) for col in self.conf_cols) - ) + ).rstrip() for k,v in self.data.items(): if k == 'TOTAL': @@ -107,4 +107,4 @@ class TwGetBalance(MMGenObject,metaclass=AsyncInit): if v['spendable']: yield red(f'Warning: this wallet contains PRIVATE KEYS for {k} outputs!') - return '\n'.join(gen_output()).rstrip() + return '\n'.join(gen_output()) diff --git a/mmgen/tw/json.py b/mmgen/tw/json.py index 844e28a3..44c6697d 100755 --- a/mmgen/tw/json.py +++ b/mmgen/tw/json.py @@ -69,7 +69,7 @@ class TwJSON: cls = json_encoder, sort_keys = True, separators = None if pretty else (',', ':'), - indent = 4 if pretty else None ) + indent = 4 if pretty else None ) + ('\n' if pretty else '') def make_chksum(self,data): return make_chksum_8( self.json_dump(data).encode() ).lower() diff --git a/mmgen/tw/view.py b/mmgen/tw/view.py index 0759280b..f1dc2a0d 100755 --- a/mmgen/tw/view.py +++ b/mmgen/tw/view.py @@ -23,6 +23,7 @@ tw.view: base class for tracking wallet view classes import sys,time,asyncio from collections import namedtuple +from ..cfg import gc,gv from ..objmethods import Hilite,InitErrors,MMGenObject from ..obj import get_obj,MMGenIdx,MMGenList from ..color import nocolor,yellow,green,red,blue @@ -412,7 +413,8 @@ class TwView(MMGenObject,metaclass=AsyncInit): yield '' if data and dt.colhdr_fmt_method: - yield getattr(self,dt.colhdr_fmt_method)(cw,hdr_fs,color) + col_hdr = getattr(self,dt.colhdr_fmt_method)(cw,hdr_fs,color) + yield col_hdr.rstrip() if line_processing == 'print' else col_hdr def get_body(method): if line_processing: @@ -441,6 +443,9 @@ class TwView(MMGenObject,metaclass=AsyncInit): [(nocolor,yellow)[color](self.nodata_msg.ljust(self.term_width))] ) ) + if not gv.stdout.isatty(): + line_processing = 'print' + dt = getattr(self.display_type,display_type) if self.use_cached: @@ -515,7 +520,6 @@ class TwView(MMGenObject,metaclass=AsyncInit): 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']) - from ..cfg import gc self.key_mappings.update(self.scroll_keys[gc.platform]) return self.key_mappings