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.strategies import create_strategy
|
||||||
from bonobo.util.objects import get_name
|
from bonobo.util.objects import get_name
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
__all__ = []
|
__all__ = []
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,9 @@ import io
|
|||||||
import sys
|
import sys
|
||||||
from contextlib import redirect_stdout
|
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 import settings
|
||||||
from bonobo.plugins import Plugin
|
from bonobo.plugins import Plugin
|
||||||
@ -23,7 +25,6 @@ class IOBuffer():
|
|||||||
finally:
|
finally:
|
||||||
previous.close()
|
previous.close()
|
||||||
|
|
||||||
|
|
||||||
class ConsoleOutputPlugin(Plugin):
|
class ConsoleOutputPlugin(Plugin):
|
||||||
"""
|
"""
|
||||||
Outputs status information to the connected stdout. Can be a TTY, with or without support for colors/cursor
|
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 = sys.stdout
|
||||||
self.stdout = IOBuffer()
|
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__()
|
self.redirect_stdout.__enter__()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
if self.isatty:
|
if self.isatty and sys.platform != 'win32':
|
||||||
self._write(self.context.parent, rewind=True)
|
self._write(self.context.parent, rewind=True)
|
||||||
else:
|
else:
|
||||||
pass # not a tty
|
pass # not a tty
|
||||||
@ -60,6 +61,11 @@ class ConsoleOutputPlugin(Plugin):
|
|||||||
t_cnt = len(context)
|
t_cnt = len(context)
|
||||||
|
|
||||||
buffered = self.stdout.switch()
|
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]:
|
for line in buffered.split('\n')[:-1]:
|
||||||
print(line + CLEAR_EOL, file=sys.stderr)
|
print(line + CLEAR_EOL, file=sys.stderr)
|
||||||
|
|
||||||
@ -76,7 +82,7 @@ class ConsoleOutputPlugin(Plugin):
|
|||||||
else:
|
else:
|
||||||
_line = ''.join(
|
_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, ' ',
|
Style.RESET_ALL, ' ',
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user