3

Enabling terminal sequences on Windows 10+ using Python works like so:

>>> print("Hello world" + "\x1b\x5b2F")  # This doesn't do much
>>> import subprocess
>>> subprocess.run("", shell=True)  # Somehow enables terminal sequences (dark magic)
>>> print("Hello world" + "\x1b\x5b2F")  # Now this goes up in console

What kind of sorcery is this?

It just opens an empty process which closes immediately after. What does that have to do with reading terminal sequences? How does it work?

5
  • I don't know much, but the answer is likely going to be "this is implementation-independent and don't rely on it." Commented Aug 13, 2022 at 9:04
  • 1
    @David Yeah but how? Why? What's going on here? How did my life choices bring me to this moment? Commented Aug 13, 2022 at 9:11
  • 1
    Well... I can't exactly answer because I only found out about the windows terminal sequences half an hour ago and I don't usually do development with Windows; my best answer would be "because somehow CPython feels like it and does it." Commented Aug 13, 2022 at 9:16
  • I'm thinking maybe because it opens a shell process (basically an empty console in the local console), it launches cmd in the local console which updates the window to a virtual terminal Commented Aug 13, 2022 at 9:22
  • Possibly, but I'm no Windows expert and I have no idea why/how. Commented Aug 13, 2022 at 9:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.