[Python] ANSI escape code

[Python] ANSI escape code

example:

print ‘033[33;46;1m’ + ‘some red text’

033[ = ESC , escape code


ESC [ <param> ; <param> … <command>

ESC [ 0 m # reset all (colors and brightness)
ESC [ 1 m # bright
ESC [ 2 m # dim (looks same as normal brightness)
ESC [ 22 m # normal brightness

# FOREGROUND:
ESC [ 30 m # black
ESC [ 31 m # red
ESC [ 32 m # green
ESC [ 33 m # yellow
ESC [ 34 m # blue
ESC [ 35 m # magenta
ESC [ 36 m # cyan
ESC [ 37 m # white
ESC [ 39 m # reset

# BACKGROUND
ESC [ 40 m # black
ESC [ 41 m # red
ESC [ 42 m # green
ESC [ 43 m # yellow
ESC [ 44 m # blue
ESC [ 45 m # magenta
ESC [ 46 m # cyan
ESC [ 47 m # white
ESC [ 49 m # reset

# cursor positioning
ESC [ x;y H # position cursor at x,y

# clear the screen
ESC [ mode J # clear the screen. Only mode 2 (clear entire screen)
. # is supported. It should be easy to add other modes,
. # let me know if that would be useful.

Ref:

http://en.wikipedia.org/wiki/ANSI_escape_code

http://pypi.python.org/pypi/colorama

廣告

,

  1. 發表留言

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

您的留言將使用 WordPress.com 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s

%d 位部落客按了讚: