Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing encoding for Windows with non-utf-8 code page #45

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion colcon_output/event_handler/console_cohesion.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2016-2018 Dirk Thomas
# Licensed under the Apache License, Version 2.0

import sys
from collections import defaultdict

from colcon_core.event.job import JobEnded
Expand Down Expand Up @@ -36,6 +37,13 @@ def __init__(self): # noqa: D107
EventHandlerExtensionPoint.EXTENSION_POINT_VERSION, '^1.0')
self.enabled = ConsoleCohesionEventHandler.ENABLED_BY_DEFAULT
self._lines = defaultdict(list)
self.encoding = self.get_encoding()

def get_encoding(self):
if sys.platform == 'win32':
from ctypes import windll
return str(windll.kernel32.GetConsoleOutputCP())
return 'utf-8'

def __call__(self, event): # noqa: D102
data = event[0]
Expand All @@ -50,7 +58,7 @@ def __call__(self, event): # noqa: D102
msg = '--- output: {data.identifier}\n' \
.format_map(locals()) + \
b''.join(
self._lines[job]).decode() + \
self._lines[job]).decode(encoding=self.encoding) + \
'---'
print(msg, flush=True)
del self._lines[job]