timofurrer / colorful

Terminal string styling done right, in Python :snake: :tada:
MIT License
525 stars 23 forks source link

Bug: DEFAULT_ENCODE is None when no TTY allocation #10

Closed walthhy closed 6 years ago

walthhy commented 6 years ago

If there no TTY, for example run python script with ">" a file. then sys.stdout.encoding will be None.
in core.py line 212, need to set a default encode 'utf-8" when DEFAULT_ENCODE is None.

Traceback (most recent call last):
  File "main_wrapper.py", line 27, in <module>
    sys.exit(main())
  File "main_wrapper.py", line 22, in main
    return `radish_main()`
  File "/usr/lib/python2.7/site-packages/radish/errororacle.py", line 54, in _decorator
    handle_exception(e)
  File "/usr/lib/python2.7/site-packages/radish/errororacle.py", line 75, in handle_exception
    write_error(exception)
  File "/usr/lib/python2.7/site-packages/radish/errororacle.py", line 25, in write_error
    console_write("{0}: {1}".format(colorful.bold_red("Error"), colorful.red(text)))
  File "/usr/lib/python2.7/site-packages/colorful/core.py", line 532, in __call__
    return self.evaluate(string, nested)
  File "/usr/lib/python2.7/site-packages/colorful/core.py", line 519, in evaluate
    style_string(string, self.style, self.colormode, nested))
  File "/usr/lib/python2.7/site-packages/colorful/core.py", line 212, in style_string
    string = string.decode(DEFAULT_ENCODE)
TypeError: decode() argument 1 must be string, not None
timofurrer commented 6 years ago

Fixed with #12