Skip to content

Commit

Permalink
py: Use piped stdout if sys.stdout is modified, IDLE fixes (#41)
Browse files Browse the repository at this point in the history
* py: Use piped stdout if sys.stdout is modified

* py: Disable colors when in run in IDLE

* handle no subprocess.CREATE_NO_WINDOW

* second attempt

* take 3

* use special case for windows

* disable on linux

* handle interactive console

* improve interactive console detection
  • Loading branch information
extremeheat authored Jan 10, 2022
1 parent a26e5c0 commit 5856773
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/javascript/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ def is_notebook():
return True


if is_notebook():
# Modified stdout
modified_stdout = (sys.stdout != sys.__stdout__) or (getattr(sys, 'ps1', sys.flags.interactive) == '>>> ')

if is_notebook() or modified_stdout:
notebook = True
stdout = subprocess.PIPE

Expand All @@ -36,7 +39,9 @@ def supports_color():
supported_platform = plat != "Pocket PC" and (plat == "win32" or "ANSICON" in os.environ)
# isatty is not always implemented, #6223.
is_a_tty = hasattr(sys.stdout, "isatty") and sys.stdout.isatty()
if notebook:
if 'idlelib.run' in sys.modules:
return False
if notebook and not modified_stdout:
return True
return supported_platform and is_a_tty

Expand Down Expand Up @@ -108,12 +113,22 @@ def readAll():
def com_io():
global proc, stdout_thread
try:
proc = subprocess.Popen(
[NODE_BIN, dn + "/js/bridge.js"],
stdin=subprocess.PIPE,
stdout=stdout,
stderr=subprocess.PIPE,
)
if os.name == 'nt':
proc = subprocess.Popen(
[NODE_BIN, dn + "/js/bridge.js"],
stdin=subprocess.PIPE,
stdout=stdout,
stderr=subprocess.PIPE,
creationflags = subprocess.CREATE_NO_WINDOW
)
else:
proc = subprocess.Popen(
[NODE_BIN, dn + "/js/bridge.js"],
stdin=subprocess.PIPE,
stdout=stdout,
stderr=subprocess.PIPE
)

except Exception as e:
print(
"--====--\t--====--\n\nBridge failed to spawn JS process!\n\nDo you have Node.js 16 or newer installed? Get it at https://nodejs.org/\n\n--====--\t--====--"
Expand Down

0 comments on commit 5856773

Please sign in to comment.