Guest User

Untitled

a guest
May 20th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.20 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #-*- coding: utf-8 -*-
  3.  
  4. # ANSI ESCAPE CODES
  5. # são códigos impressos afim de transmitir instruções ao terminal.
  6.  
  7. print ''
  8. print '#' * 80
  9. print '\t\t\t\tANSI ESCAPE CODES'
  10. print '#' * 80
  11.  
  12. # 8 CORES
  13. # Os terminais mais básicos possuem um conjunto de 8 cores.
  14. # que variam de 30m a 37m.
  15.  
  16. print '\n1) FOREGROUND COLORS:\n'
  17.  
  18. # Black: \u001b[30m
  19. print u'\u001b[30m\\u001b[30m ou \\033[30m BLACK\u001b[0m'
  20. # Red: \u001b[31m
  21. print u'\u001b[31m\\u001b[31m ou \\033[31m RED\u001b[0m'
  22. # Green: \u001b[32m
  23. print u'\u001b[32m\\u001b[32m ou \\033[32m GREEN\u001b[0m'
  24. # Yellow: \u001b[33m
  25. print u'\u001b[33m\\u001b[33m ou \\033[33m YELLOW\u001b[0m'
  26. # Blue: \u001b[34m
  27. print u'\u001b[34m\\u001b[34m ou \\033[34m BLUE\u001b[0m'
  28. # Magenta \u001b[35m
  29. print u'\u001b[35m\\u001b[35m ou \\033[35m MAGENTA\u001b[0m'
  30. # Cyan \u001b[36m
  31. print u'\u001b[36m\\u001b[36m ou \\033[36m CYAN\u001b[0m'
  32. # White \u001b[37m
  33. print u'\u001b[37m\\u001b[37m ou \\033[37m WHITE\u001b[0m'
  34. # Reset: \u001b[0m
  35. print u'\u001b[0m\\u001b[0m ou \\033[0m RESET'
  36. print ''
  37.  
  38. # 16 CORES
  39. # Terminais com um conjunto de 16 cores suportam tons de cores (claros ou escuros).
  40. # Tom claro - bright
  41. # Tom escuro - bold
  42. # Nesse caso o ANSI code é seguido de ;1
  43.  
  44. print '\n2) FOREGROUND COLORS WITH SHADES (BRIGHT OR BOLD):\n'
  45. # Bright Black
  46. print u'\u001b[30;1m\\u001b[30;1m ou \\033[30;1m BRIGHT BLACK\u001b[0m'
  47. # Bright Red
  48. print u'\u001b[31;1m\\u001b[31;1m ou \\033[31;1m BRIGHT RED\u001b[0m'
  49. # Bright Green
  50. print u'\u001b[32;1m\\u001b[32;1m ou \\033[32;1m BRIGHT GREEN\u001b[0m'
  51. # Bright Yellow
  52. print u'\u001b[33;1m\\u001b[33;1m ou \\033[33;1m BRIGHT YELLOW\u001b[0m'
  53. # Bright Blue
  54. print u'\u001b[34;1m\\u001b[34;1m ou \\033[34;1m BRIGHT BLUE\u001b[0m'
  55. # Bright Magenta
  56. print u'\u001b[35;1m\\u001b[35;1m ou \\033[35;1m BRIGHT MAGENTA\u001b[0m'
  57. # Bright Cyan
  58. print u'\u001b[36;1m\\u001b[36;1m ou \\033[36;1m BRIGHT CYAN\u001b[0m'
  59. # Bright White
  60. print u'\u001b[37;1m\\u001b[37;1m ou \\033[37;1m BRIGHT WHITE\u001b[0m'
  61.  
  62. # 256 CORES
  63. # Alguns terminais suportam um conjunto de cores extendido de 256 cores.
  64. import sys
  65. for i in range(0, 16):
  66. for j in range(0, 16):
  67. code = str(i * 16 + j)
  68. sys.stdout.write(u'\u001b[38;5;' + code + 'm ' + code.ljust(4))
  69. print u'\u001b[0m'
  70.  
  71. # BACKGROUND COLORS
  72. # Variam de 40m a 47m
  73. print ''
  74. print '3) BACKGROUND COLORS:'
  75. print ''
  76. # Background Black
  77. print u'\u001b[40m\\u001b[40m ou \\033[40m BACKGROUND BLACK\u001b[0m'
  78. # Background Bright Black
  79. print u'\u001b[40;1m\\u001b[40;1m ou \\033[40;1m BACKGROUND BRIGHT BLACK\u001b[m'
  80. # Background Red
  81. print u'\u001b[41m\\u001b[41m ou \\033[41m BACKGROUND RED\u001b[0m'
  82. # Background Bright Red
  83. print u'\u001b[41;1m\\u001b[41;1m ou \\033[41;1m BACKGROUND BRIGHT RED\u001b[0m'
  84. # Background Green
  85. print u'\u001b[42m\\u001b[42m ou \\033[42m BACKGROUND GREEN\u001b[0m'
  86. # Background Bright Green
  87. print u'\u001b[42;1m\\u001b[42;1m ou \\033[42;1m BACKGROUND BRIGHT GREEN\u001b[0m'
  88. # Background Yellow
  89. print u'\u001b[43m\\u001b[43m ou \\033[43m BACKGROUND YELLOW\u001b[0m'
  90. # Background Bright Yellow
  91. print u'\u001b[43;1m\\u001b[43;1m ou \\033[43;1m BACKGROUND BRIGHT YELLOW\u001b[0m'
  92. # Background Blue
  93. print u'\u001b[44m\\u001b[44m ou \\033[44m BACKGROUND BLUE\u001b[0m'
  94. # Background Bright Blue
  95. print u'\u001b[44;1m\\u001b[44;1m ou \\033[44;1m BACKGROUND BRIGHT BLUE\u001b[0m'
  96. # Background Magenta
  97. print u'\u001b[45m\\u001b[45m ou \\033[45m BACKGROUND MAGENTA\u001b[0m'
  98. # Background Bright Magenta
  99. print u'\u001b[45;1m\\u001b[45;1m ou \\033[45;1m BACKGROUND BRIGHT MAGENTA\u001b[0m'
  100. # Background Cyan
  101. print u'\u001b[46m\\u001b[46m ou \\033[46m BACKGROUND CYAN\u001b[0m'
  102. # Background Bright Cyan
  103. print u'\u001b[46;1m\\u001b[46;1m ou \\033[46;1m BACKGROUND BRIGHT CYAN\u001b[0m'
  104. # Background White
  105. print u'\u001b[47m\\u001b[47m ou \\033[47m BACKGROUND WHITE\u001b[0m'
  106. # Background Bright White
  107. print u'\u001b[47;1m\\u001b[47;1m ou \\033[47;1m BACKGROUND BRIGHT WHITE\u001b[0m'
  108.  
  109. for i in range(0, 16):
  110. for j in range(0, 16):
  111. code = str(i * 16 + j)
  112. sys.stdout.write(u'\u001b[48;5;' + code + 'm ' + code.ljust(4))
  113. print u'\u001b[0m'
  114.  
  115. print ''
  116. # DECORAÇÕES
  117. # Bold \u001b[1m
  118. # Underline \u001b[4m
  119. # Reversed \u001b[7m
  120. print u'\u001b[1m\\001b[1m ou \\033[1m BOLD\u001b[0m'
  121. print u'\u001b[4m\\001b[4m ou \\033[4m UNDERLINE\u001b[0m'
  122. print u'\u001b[7m\\001b[7m ou \\033[7m REVERSED\u001b[0m'
  123.  
  124. print u'\u001b[1m\u001b[4m\u001b[7mHELLO ANSI ESCAPE CODES!!!\u001b[0m'
  125.  
  126. # CURSOR NAVIGATION
  127. # Up \u001b[{n}A
  128. # Down \u001b[{n}B
  129. # Right \u001b[{n}C
  130. # Left \u001b[{n}D
  131.  
  132. # Progress Indicator
  133. import time
  134.  
  135. def loading():
  136. print 'Loading...'
  137. for i in range(0, 100):
  138. time.sleep(0.1)
  139. sys.stdout.write(u'\u001b[1000D' + str(i + 1) + '%')
  140. sys.stdout.flush()
  141. print
  142. loading()
  143.  
  144. def slow_loading():
  145. print 'Loading...'
  146. for i in range(0, 100):
  147. time.sleep(1)
  148. sys.stdout.write(u'\u001b[1000D')
  149. sys.stdout.flush()
  150. time.sleep(1)
  151. sys.stdout.write(str(i + 1) + '%')
  152. sys.stdout.flush()
  153. print
  154. slow_loading()
  155.  
  156. def progressbar():
  157. print 'Loading...'
  158. for i in range(0, 100):
  159. time.sleep(0.1)
  160. width = (i + 1) / 4
  161. bar = '[' + '#' * width + ' ' * (25 - width) + ']'
  162. sys.stdout.write(u'\u001b[1000D' + bar)
  163. sys.stdout.flush()
  164. print
  165. progressbar()
Add Comment
Please, Sign In to add comment