Skip to content

Commit

Permalink
Merge pull request #924 from Carreau/no-coloransi
Browse files Browse the repository at this point in the history
Remove reliance on IPython's coloransi
  • Loading branch information
minrk authored Feb 11, 2025
2 parents 46172fe + 590bfa3 commit dc74dcc
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions ipyparallel/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from IPython.core.profiledir import ProfileDir, ProfileDirError
from IPython.paths import get_ipython_dir
from IPython.utils.capture import RichOutput
from IPython.utils.coloransi import TermColors
from IPython.utils.path import compress_user
from jupyter_client.localinterfaces import is_local_ip, localhost
from jupyter_client.session import Session
Expand Down Expand Up @@ -155,37 +154,18 @@ def __repr__(self):

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

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

if not text_out:
return ''

ip = get_ipython()
if ip is None:
colors = "NoColor"
else:
colors = ip.colors

if colors == "NoColor":
out = normal = ""
else:
out = TermColors.Red
normal = TermColors.Normal

if '\n' in text_out and not text_out.startswith('\n'):
# add newline for multiline reprs
text_out = '\n' + text_out

return ''.join(
[
out,
f"Out[{self.metadata['engine_id']}:{self.execution_count}]: ",
normal,
text_out,
]
)
return f"Out[{self.metadata['engine_id']}:{self.execution_count}]: {text_out}"

def _repr_pretty_(self, p, cycle):
p.text(self._plaintext())
Expand Down

0 comments on commit dc74dcc

Please sign in to comment.