Closed ofek closed 2 years ago
What you're trying to demonstrate can be done with:
>>> import io
>>> import os
>>> import blessed
>>> stream = io.StringIO()
>>> os.environ['TERM'] = ""
>>> term = blessed.Terminal(stream=stream, force_styling=True)
>>> term.bold_red('test TTY')
'test TTY'
The problem is not that it's not a TTY, but that you don't have a TERM environment variable and you haven't specified kind
when initializing Terminal. Essentially the library is honoring force_styling
, but doesn't know what terminal type to use or terminal capabilities, so assumes a null one with no capabilities.
Restart REPL before running this
>>> import io
>>> import os
>>> import blessed
>>> stream = io.StringIO()
>>> os.environ['TERM'] = ""
>>> term = blessed.Terminal(stream=stream, force_styling=True, kind='xterm')
>>> term.bold_red('test TTY')
'\x1b[1m\x1b[31mtest TTY\x1b(B\x1b[m'
Ah, thanks! So when forcing one must also set kind
. Is xterm
the preferred value or are there others?
Well, I would say you should set kind
if it can not be automatically determined or you want to be specific.
xterm or xterm-256color are the most common and what most terminals emulate these days. If you're just doing basic colors, xterm is fine. It really just depends on your use case.
Thank you!
Can be seen in https://github.com/jquast/blessed/pull/232 if you click run