Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ansi_colors = {
- None: 'x1b[0m', # actually black but whatevs
- 'red': 'x1b[31m',
- 'green' : 'x1b[32m',
- ...
- }
- param result
- 0 reset all attributes to their defaults
- 1 set bold
- 2 set half-bright (simulated with color on a color display)
- 4 set underscore (simulated with color on a color display) (the colors used to
- simulate dim or underline are set using ESC ] ...)
- 5 set blink
- 7 set reverse video
- 10 reset selected mapping, display control flag, and toggle meta flag (ECMA-48
- says "primary font").
- 11 select null mapping, set display control flag, reset toggle meta flag
- (ECMA-48 says "first alternate font").
- 12 select null mapping, set display control flag, set toggle meta flag (ECMA-48
- says "second alternate font"). The toggle meta flag causes the high bit of a
- byte to be toggled before the mapping table translation is done.
- 21 set normal intensity (ECMA-48 says "doubly underlined")
- 22 set normal intensity
- 24 underline off
- 25 blink off
- 27 reverse video off
- 30 set black foreground
- 31 set red foreground
- 32 set green foreground
- 33 set brown foreground
- 34 set blue foreground
- 35 set magenta foreground
- 36 set cyan foreground
- 37 set white foreground
- 38 set underscore on, set default foreground color
- 39 set underscore off, set default foreground color
- 40 set black background
- 41 set red background
- 42 set green background
- 43 set brown background
- 44 set blue background
- 45 set magenta background
- 46 set cyan background
- 47 set white background
- 49 set default background color
- import curses
- def fcolor(c):
- return 'x1B[{0}m'.format(30 + c)
- def bcolor(c):
- return 'x1B[{0}m'.format(40 + c)
- def fbcolor(f, b):
- return 'x1B[{0};{1}m'.format(30 + f, 40 + b)
- print(fbcolor(curses.COLOR_RED, curses.COLOR_YELLOW) + "hello!")
- tput setaf 4
- import curses
- curses.setupterm()
- curses.putp(curses.tparm(curses.tigetstr("setaf"), curses.COLOR_RED))
- curses.putp(curses.tparm(curses.tigetstr("setab"), curses.COLOR_YELLOW))
- curses.putp("hello!")
- curses.putp(curses.tigetstr("sgr0"))
- curses.putp("n")
- def fcolor(c):
- if c>7:
- return 'x1B[1;{0}m'.format(22 + c)
- else:
- return 'x1B[0;{0}m'.format(30 + c)
- def bcolor(c):
- return 'x1B[{0}m'.format(40 + c)
- def fbcolor(f, b):
- if f>7:
- return 'x1B[1;{0};{1}m'.format(22 + f, 40 + b)
- else:
- return 'x1B[0;{0};{1}m'.format(30 + f, 40 + b)
Add Comment
Please, Sign In to add comment