How does jupyter recognize the font color ?

43 views
Skip to first unread message

Jeff Zhang

unread,
Jul 6, 2017, 11:11:50 AM7/6/17
to Project Jupyter
I use jupyter_client to execute some python code `range?`, and the result has some special characters as following which I believe it is for font color. Because I notice the font color when I run `range?` in ipython.

Could you anyone point me how jupyter recognize the font color via these specia characters ? Is there standards for that ? Thanks



[{'data': {'text/plain': '\x1b[0;31mInit signature:\x1b[0m \x1b[0mrange\x1b[0m\x1b[0;34m(\x1b[0m\x1b[0mself\x1b[0m\x1b[0;34m,\x1b[0m \x1b[0;34m/\x1b[0m\x1b[0;34m,\x1b[0m \x1b[0;34m*\x1b[0m\x1b[0margs\x1b[0m\x1b[0;34m,\x1b[0m \x1b[0;34m**\x1b[0m\x1b[0mkwargs\x1b[0m\x1b[0;34m)\x1b[0m\x1b[0;34m\x1b[0m\x1b[0m\n\x1b[0;31mDocstring:\x1b[0m     \nrange(stop) -> range object\nrange(start, stop[, step]) -> range object\n\nReturn an object that produces a sequence of integers from start (inclusive)\nto stop (exclusive) by step.  range(i, j) produces i, i+1, i+2, ..., j-1.\nstart defaults to 0, and stop is omitted!  range(4) produces 0, 1, 2, 3.\nThese are exactly the valid indices for a list of 4 elements.\nWhen step is given, it specifies the increment (or decrement).\n\x1b[0;31mType:\x1b[0m           type\n'},
  'source': 'page',
  'start': 0}]

Thomas Kluyver

unread,
Jul 6, 2017, 1:00:18 PM7/6/17
to Project Jupyter
On 6 July 2017 at 16:11, Jeff Zhang <zjf...@gmail.com> wrote:
Could you anyone point me how jupyter recognize the font color via these specia characters ? Is there standards for that ? Thanks

Hi Jeff,

These are ANSI escape codes. They're typically recognised by your terminal emulator, and our non-terminal frontends (notebook, qtconsole) have specific code to process them and show the colours. Wikipedia has some good info on them:
https://en.wikipedia.org/wiki/ANSI_escape_code

The ones we use are mainly the SGR ('Select Graphics Rendition') codes.

Thomas

Jeff Zhang

unread,
Jul 6, 2017, 8:20:08 PM7/6/17
to Project Jupyter

Thanks Thomas.


在 2017年7月7日星期五 UTC+8上午1:00:18,takowl写道:

Kyle Kelley

unread,
Jul 6, 2017, 8:55:19 PM7/6/17
to jup...@googlegroups.com
Depending on what your frontend is written in, there are many libraries for turning ANSI text into HTML (or React elements):





--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscribe@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/f0942aa9-e06d-4c04-9153-54108937dc24%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Kyle Kelley (@rgbkrklambdaops.com)
Reply all
Reply to author
Forward
0 new messages