Guest User

Untitled

a guest
Jun 21st, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. ansi_colors = {
  2. None: 'x1b[0m', # actually black but whatevs
  3. 'red': 'x1b[31m',
  4. 'green' : 'x1b[32m',
  5. ...
  6. }
  7.  
  8. param result
  9. 0 reset all attributes to their defaults
  10. 1 set bold
  11. 2 set half-bright (simulated with color on a color display)
  12. 4 set underscore (simulated with color on a color display) (the colors used to
  13. simulate dim or underline are set using ESC ] ...)
  14. 5 set blink
  15. 7 set reverse video
  16. 10 reset selected mapping, display control flag, and toggle meta flag (ECMA-48
  17. says "primary font").
  18. 11 select null mapping, set display control flag, reset toggle meta flag
  19. (ECMA-48 says "first alternate font").
  20. 12 select null mapping, set display control flag, set toggle meta flag (ECMA-48
  21. says "second alternate font"). The toggle meta flag causes the high bit of a
  22. byte to be toggled before the mapping table translation is done.
  23. 21 set normal intensity (ECMA-48 says "doubly underlined")
  24. 22 set normal intensity
  25. 24 underline off
  26. 25 blink off
  27. 27 reverse video off
  28. 30 set black foreground
  29. 31 set red foreground
  30. 32 set green foreground
  31. 33 set brown foreground
  32. 34 set blue foreground
  33. 35 set magenta foreground
  34. 36 set cyan foreground
  35. 37 set white foreground
  36. 38 set underscore on, set default foreground color
  37. 39 set underscore off, set default foreground color
  38. 40 set black background
  39. 41 set red background
  40. 42 set green background
  41. 43 set brown background
  42. 44 set blue background
  43. 45 set magenta background
  44. 46 set cyan background
  45. 47 set white background
  46. 49 set default background color
  47.  
  48. import curses
  49. def fcolor(c):
  50. return 'x1B[{0}m'.format(30 + c)
  51. def bcolor(c):
  52. return 'x1B[{0}m'.format(40 + c)
  53. def fbcolor(f, b):
  54. return 'x1B[{0};{1}m'.format(30 + f, 40 + b)
  55.  
  56. print(fbcolor(curses.COLOR_RED, curses.COLOR_YELLOW) + "hello!")
  57.  
  58. tput setaf 4
  59.  
  60. import curses
  61.  
  62. curses.setupterm()
  63. curses.putp(curses.tparm(curses.tigetstr("setaf"), curses.COLOR_RED))
  64. curses.putp(curses.tparm(curses.tigetstr("setab"), curses.COLOR_YELLOW))
  65. curses.putp("hello!")
  66. curses.putp(curses.tigetstr("sgr0"))
  67. curses.putp("n")
  68.  
  69. def fcolor(c):
  70. if c>7:
  71. return 'x1B[1;{0}m'.format(22 + c)
  72. else:
  73. return 'x1B[0;{0}m'.format(30 + c)
  74. def bcolor(c):
  75. return 'x1B[{0}m'.format(40 + c)
  76. def fbcolor(f, b):
  77. if f>7:
  78. return 'x1B[1;{0};{1}m'.format(22 + f, 40 + b)
  79. else:
  80. return 'x1B[0;{0};{1}m'.format(30 + f, 40 + b)
Add Comment
Please, Sign In to add comment