better windows console output
This commit is contained in:
@ -4,6 +4,8 @@ from bonobo.nodes import CsvReader, CsvWriter, FileReader, FileWriter, Filter, J
|
||||
from bonobo.strategies import create_strategy
|
||||
from bonobo.util.objects import get_name
|
||||
|
||||
|
||||
|
||||
__all__ = []
|
||||
|
||||
|
||||
|
||||
@ -2,7 +2,9 @@ import io
|
||||
import sys
|
||||
from contextlib import redirect_stdout
|
||||
|
||||
from colorama import Style, Fore
|
||||
from colorama import Style, Fore, init
|
||||
init(wrap=True)
|
||||
|
||||
|
||||
from bonobo import settings
|
||||
from bonobo.plugins import Plugin
|
||||
@ -23,7 +25,6 @@ class IOBuffer():
|
||||
finally:
|
||||
previous.close()
|
||||
|
||||
|
||||
class ConsoleOutputPlugin(Plugin):
|
||||
"""
|
||||
Outputs status information to the connected stdout. Can be a TTY, with or without support for colors/cursor
|
||||
@ -43,11 +44,11 @@ class ConsoleOutputPlugin(Plugin):
|
||||
|
||||
self._stdout = sys.stdout
|
||||
self.stdout = IOBuffer()
|
||||
self.redirect_stdout = redirect_stdout(self.stdout)
|
||||
self.redirect_stdout = redirect_stdout(self.stdout if sys.platform != 'win32' else self._stdout)
|
||||
self.redirect_stdout.__enter__()
|
||||
|
||||
def run(self):
|
||||
if self.isatty:
|
||||
if self.isatty and sys.platform != 'win32':
|
||||
self._write(self.context.parent, rewind=True)
|
||||
else:
|
||||
pass # not a tty
|
||||
@ -60,6 +61,11 @@ class ConsoleOutputPlugin(Plugin):
|
||||
t_cnt = len(context)
|
||||
|
||||
buffered = self.stdout.switch()
|
||||
|
||||
if sys.platform == 'win32':
|
||||
for line in buffered.split('\n')[:-1]:
|
||||
print(line, file=sys.stderr)
|
||||
else:
|
||||
for line in buffered.split('\n')[:-1]:
|
||||
print(line + CLEAR_EOL, file=sys.stderr)
|
||||
|
||||
@ -76,7 +82,7 @@ class ConsoleOutputPlugin(Plugin):
|
||||
else:
|
||||
_line = ''.join(
|
||||
(
|
||||
' ', Fore.BLACK, '-', ' ', node.name, name_suffix, ' ', node.get_statistics_as_string(),
|
||||
' ', Style.BRIGHT+Fore.BLACK, '-', ' ', node.name, name_suffix, ' ', node.get_statistics_as_string(),
|
||||
Style.RESET_ALL, ' ',
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user