Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion colorama/ansitowin32.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ def convert_osc(self, text):
# 1 - change icon (we don't support this)
# 2 - change title
if params[0] in '02':
winterm.set_title(params[1])
if self.convert and winterm:
winterm.set_title(params[1])
return text


Expand Down
9 changes: 9 additions & 0 deletions colorama/tests/ansitowin32_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@ def test_osc_codes(self):
stream.write(code)
self.assertEqual(winterm.set_title.call_count, 2)

def test_osc_codes_not_converted_when_stripping(self):
# Issue #407: with strip=True and convert=False (e.g. no PTY on Linux),
# OSC title sequences must be stripped without touching winterm, which
# is None on non-Windows platforms. Calling it would raise AttributeError.
mockStdout = Mock()
with patch('colorama.ansitowin32.winterm', None):
stream = AnsiToWin32(mockStdout, strip=True, convert=False)
stream.write('\033]2;colorama_test_title\x07') # must not raise

def test_native_windows_ansi(self):
with ExitStack() as stack:
def p(a, b):
Expand Down