color.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import sys
  2. class Colors:
  3. ENDC = '\033[m'
  4. GREEN = '\033[32m'
  5. GREY = '\033[90m'
  6. def macop_text(msg):
  7. """Display Macop message to user interface
  8. """
  9. return Colors.GREEN + 'M' + Colors.ENDC + Colors.GREY + 'acop' \
  10. + Colors.ENDC + Colors.GREEN + ' :: ' + Colors.ENDC \
  11. + Colors.GREY + msg + Colors.ENDC
  12. def macop_line():
  13. """Macop split line
  14. """
  15. line = ''
  16. for i in range(41):
  17. if i % 2 == 0:
  18. line += Colors.GREEN + '----' + Colors.ENDC
  19. else:
  20. line += Colors.GREY + '----' + Colors.ENDC
  21. return line
  22. def macop_progress(evaluations, max):
  23. barWidth = 156
  24. progress = evaluations / float(max)
  25. output_str = Colors.GREEN + '[' + Colors.ENDC
  26. pos = int(barWidth * progress)
  27. for i in range(barWidth):
  28. if i < pos:
  29. output_str = output_str + Colors.GREY + '=' + Colors.ENDC
  30. elif i == pos:
  31. output_str = output_str + Colors.GREEN + '>' + Colors.ENDC
  32. else:
  33. output_str = output_str + Colors.GREY + ' ' + Colors.ENDC
  34. output_str = output_str + Colors.GREEN + '] ' + Colors.ENDC + str(
  35. int(progress * 100.0)) + "%\r"
  36. print(output_str)
  37. sys.stdout.write("\033[F")
  38. # go to line
  39. if progress >= 1.:
  40. print()
  41. print(macop_line())