Advertisement
Mark2020H

Code for colouring console text and slow printing

Mar 25th, 2020
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.06 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3.  
  4. import argparse
  5. import time
  6. import sys
  7. import os
  8.  
  9.  
  10. # Author MD Harrington  facebook https://www.facebook.com/mark.harrington.142892 links to this there as well for you
  11. # code that prinst a text file to console  with colous set on chars in slow motion type writer effect
  12. # usage ::  python.py <yourfile.txt>
  13. # global colour settings
  14. # python version Python 2.7.14
  15.  
  16.  
  17. CBLACK  = '\33[30m'
  18. CRED    = '\33[31m'
  19. CGREEN  = '\33[32m'
  20. CYELLOW = '\33[33m'
  21. CBLUE   = '\33[34m'
  22. CVIOLET = '\33[35m'
  23. CBEIGE  = '\33[36m'
  24. CWHITE  = '\33[37m'
  25. CYAN  = "\033[1;36m"
  26.  
  27. CBLACKBG  = '\33[40m'
  28. CREDBG    = '\33[41m'
  29. CGREENBG  = '\33[42m'
  30. CYELLOWBG = '\33[43m'
  31. CBLUEBG   = '\33[44m'
  32. CVIOLETBG = '\33[45m'
  33. CBEIGEBG  = '\33[46m'
  34. CWHITEBG  = '\33[47m'
  35.  
  36. CGREY    = '\33[90m'
  37. CRED2    = '\33[91m'
  38. CGREEN2  = '\33[92m'
  39. CYELLOW2 = '\33[93m'
  40. CBLUE2   = '\33[94m'
  41. CVIOLET2 = '\33[95m'
  42. CBEIGE2  = '\33[96m'
  43. CWHITE2  = '\33[97m'
  44.  
  45. CGREYBG    = '\33[100m'
  46. CREDBG2    = '\33[101m'
  47. CGREENBG2  = '\33[102m'
  48. CYELLOWBG2 = '\33[103m'
  49. CBLUEBG2   = '\33[104m'
  50. CVIOLETBG2 = '\33[105m'
  51. CBEIGEBG2  = '\33[106m'
  52. CWHITEBG2  = '\33[107m'
  53. ENDC = '\033[0m'
  54.  
  55. parser = argparse.ArgumentParser(description='Open file .')
  56. parser.add_argument('v1', type = str , help='imput your file to be opened')
  57.  
  58. args=parser.parse_args();
  59.  
  60. m_file = args.v1
  61.  
  62. def f_clearscreen(time_delay):
  63.     os.system('clear')
  64.     time.sleep(time_delay)
  65.     for x in range(3):
  66.         print('')
  67.    
  68.    
  69.  
  70.  
  71. def f_openfile(fileopen):
  72.      # make this global so that functions can see this
  73.     global lines
  74.     f = open(fileopen, "r")
  75.         # use readlines to read all lines in the file
  76.         # The variable "lines" is a list containing all lines in the file
  77.     lines = f.readlines()
  78.    
  79.     # close the file after reading the lines.
  80.     f.close()
  81.    
  82.  
  83. def slowPrint():
  84.    
  85.     for line in lines:
  86.         for mychar in line:
  87.             sys.stdout.write(CYAN + mychar)
  88.             sys.stdout.flush()
  89.             time.sleep(0.05)
  90.     sys.stdout.write(ENDC)
  91.     sys.stdout.flush()
  92.  
  93. f_clearscreen(3.00)
  94.  
  95. f_openfile(m_file)
  96.  
  97. slowPrint()
  98. time.sleep(2)
  99. os.system('clear')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement