1
0

nant-color 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/ruby
  2. def main
  3. IO.popen("nant #{ARGV.join(' ')}") { |pipe|
  4. pipe.sync = true
  5. while str = pipe.gets
  6. str.sub!(/\n+/, '')
  7. puts colorize(str)
  8. end
  9. }
  10. end
  11. def clear
  12. return "\e[0m"
  13. end
  14. def red(str)
  15. return "\e[31m" + str + clear
  16. end
  17. def green(str)
  18. return "\e[32m" + str + clear
  19. end
  20. def yellow(str)
  21. return "\e[33m" + str + clear
  22. end
  23. def black
  24. return "\e[30m"
  25. end
  26. def hide
  27. return "\e[8m"
  28. end
  29. def bright
  30. return "\e[1m"
  31. end
  32. def colorize(str)
  33. str.sub!(/(error \w+:.*)/, red('\1'))
  34. str.sub!(/(warning \w+:.*)/, yellow('\1'))
  35. str.sub!(/(Build Succeeded)/i, green('\1'))
  36. str.sub!(/(Compilation succeeded)/, green('\1'))
  37. str.sub!(/(\d+ warning\(s\))/, yellow('\1'))
  38. str.sub!(/(Build Failed)/i, red('\1'))
  39. str.sub!(/(Tests run: \d+, Failures: 0, Not run: 0,.*)/, green('\1'))
  40. str.sub!(/(Tests run: \d+, Failures: 0, Not run: [1-9].*)/, yellow('\1'))
  41. str.sub!(/(Tests run: \d+, Failures: [1-9].*)/, red('\1'))
  42. str.sub!(/(Test Case Failures:)/, red('\1'))
  43. return str
  44. end
  45. main()