|
@@ -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')
|