Skip to content

Commit ba5f31d

Browse files
authored
Revert "Remove reliance on IPython's coloransi"
1 parent d9670ba commit ba5f31d

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

ipyparallel/client/client.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from IPython.core.profiledir import ProfileDir, ProfileDirError
2727
from IPython.paths import get_ipython_dir
2828
from IPython.utils.capture import RichOutput
29+
from IPython.utils.coloransi import TermColors
2930
from IPython.utils.path import compress_user
3031
from jupyter_client.localinterfaces import is_local_ip, localhost
3132
from jupyter_client.session import Session
@@ -154,18 +155,37 @@ def __repr__(self):
154155

155156
return f"<ExecuteReply[{self.execution_count}]: {text_out}>"
156157

157-
def _plaintext(self) -> str:
158+
def _plaintext(self):
158159
execute_result = self.metadata['execute_result'] or {'data': {}}
159160
text_out = execute_result['data'].get('text/plain', '')
160161

161162
if not text_out:
162163
return ''
163164

165+
ip = get_ipython()
166+
if ip is None:
167+
colors = "NoColor"
168+
else:
169+
colors = ip.colors
170+
171+
if colors == "NoColor":
172+
out = normal = ""
173+
else:
174+
out = TermColors.Red
175+
normal = TermColors.Normal
176+
164177
if '\n' in text_out and not text_out.startswith('\n'):
165178
# add newline for multiline reprs
166179
text_out = '\n' + text_out
167180

168-
return f"Out[{self.metadata['engine_id']}:{self.execution_count}]: {text_out}"
181+
return ''.join(
182+
[
183+
out,
184+
f"Out[{self.metadata['engine_id']}:{self.execution_count}]: ",
185+
normal,
186+
text_out,
187+
]
188+
)
169189

170190
def _repr_pretty_(self, p, cycle):
171191
p.text(self._plaintext())

0 commit comments

Comments
 (0)