Skip to content

Commit eac38f0

Browse files
committed
Don't break ANSI to HTML conversion on output encoding errors
1 parent 9d4e24a commit eac38f0

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

coloredlogs/cli.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Command line interface for the coloredlogs package.
22
#
33
# Author: Peter Odding <[email protected]>
4-
# Last Change: October 14, 2015
4+
# Last Change: May 18, 2017
55
# URL: https://coloredlogs.readthedocs.io
66

77
"""
@@ -44,7 +44,7 @@
4444
import webbrowser
4545

4646
# External dependencies.
47-
from humanfriendly.terminal import connected_to_terminal, usage
47+
from humanfriendly.terminal import connected_to_terminal, output, usage, warning
4848

4949
# Modules included in our package.
5050
from coloredlogs.converter import capture, convert
@@ -55,7 +55,7 @@
5555

5656

5757
def main():
58-
"""Command line interface for the `coloredlogs` program."""
58+
"""Command line interface for the ``coloredlogs`` program."""
5959
actions = []
6060
try:
6161
# Parse the command line arguments.
@@ -78,7 +78,7 @@ def main():
7878
usage(__doc__)
7979
return
8080
except Exception as e:
81-
sys.stderr.write("Error: %s\n" % e)
81+
warning("Error: %s", e)
8282
sys.exit(1)
8383
for function in actions:
8484
function()
@@ -92,11 +92,11 @@ def convert_command_output(*command):
9292
(emulating an interactive terminal), intercepts the output of the command
9393
and converts ANSI escape sequences in the output to HTML.
9494
"""
95-
html_output = convert(capture(command))
95+
html = convert(capture(command))
9696
if connected_to_terminal():
9797
fd, temporary_file = tempfile.mkstemp(suffix='.html')
9898
with open(temporary_file, 'w') as handle:
99-
handle.write(html_output)
99+
handle.write(html)
100100
webbrowser.open(temporary_file)
101101
else:
102-
print(html_output)
102+
output(html)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
humanfriendly >= 2.1
1+
humanfriendly >= 3.2

0 commit comments

Comments
 (0)