Skip to content

Commit 2ec4cbf

Browse files
authored
Merge pull request #683 from peendebak/master
Make the isatty method of OutStream return True
2 parents fda1156 + abbcc0e commit 2ec4cbf

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

ipykernel/iostream.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def _watch_pipe_fd(self):
320320
self._exc = sys.exc_info()
321321

322322
def __init__(
323-
self, session, pub_thread, name, pipe=None, echo=None, *, watchfd=True
323+
self, session, pub_thread, name, pipe=None, echo=None, *, watchfd=True, isatty=False,
324324
):
325325
"""
326326
Parameters
@@ -333,6 +333,8 @@ def __init__(
333333
the file descriptor by its number. It will spawn a watching thread,
334334
that will swap the give file descriptor for a pipe, read from the
335335
pipe, and insert this into the current Stream.
336+
isatty : bool (default, False)
337+
Indication of whether this stream has termimal capabilities (e.g. can handle colors)
336338
337339
"""
338340
if pipe is not None:
@@ -364,6 +366,7 @@ def __init__(
364366
self._io_loop = pub_thread.io_loop
365367
self._new_buffer()
366368
self.echo = None
369+
self._isatty = bool(isatty)
367370

368371
if (
369372
watchfd
@@ -381,6 +384,14 @@ def __init__(
381384
else:
382385
raise ValueError("echo argument must be a file like object")
383386

387+
def isatty(self):
388+
"""Return a bool indicating whether this is an 'interactive' stream.
389+
390+
Returns:
391+
Boolean
392+
"""
393+
return self._isatty
394+
384395
def _setup_stream_redirects(self, name):
385396
pr, pw = os.pipe()
386397
fno = getattr(sys, name).fileno()

ipykernel/tests/test_io.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,13 @@ def test_io_api():
3838
stream.seek(0)
3939
with nt.assert_raises(io.UnsupportedOperation):
4040
stream.tell()
41+
42+
def test_io_isatty():
43+
session = Session()
44+
ctx = zmq.Context()
45+
pub = ctx.socket(zmq.PUB)
46+
thread = IOPubThread(pub)
47+
thread.start()
48+
49+
stream = OutStream(session, thread, 'stdout', isatty=True)
50+
assert stream.isatty()

0 commit comments

Comments
 (0)