PageRenderTime 185ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/tools/PhyreFly/src/PFConsole.cs

https://bitbucket.org/drummertom999/phyreballs
C# | 61 lines | 51 code | 10 blank | 0 comment | 6 complexity | c8e9e6924be808a64710b28f3384e0dd MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Drawing;
  6. namespace PhyreFly
  7. {
  8. class PFConsole
  9. {
  10. private static Color[] m_colours = { Color.White, Color.Green, Color.Orange, Color.Red };
  11. public enum Severity { INFO = 0, SUCCESS, WARNING, ERROR };
  12. public static string SpreadText(string text)
  13. {
  14. bool bInToken = false;
  15. string spreadText = string.Empty;
  16. text = text.Replace(" ", " ");
  17. foreach (char c in text)
  18. {
  19. bInToken = (c == '{' || (bInToken && c != '}'));
  20. spreadText += c + (bInToken ? "" : " ");
  21. }
  22. return spreadText;
  23. }
  24. public static void WriteHeading(Severity severity, string msg, params object[] args)
  25. {
  26. WriteLine(severity, "\r\n***********************************************");
  27. WriteLine(severity, " " + SpreadText(msg), args);
  28. WriteLine(severity, "***********************************************");
  29. }
  30. public static void WriteLine(Color severity, string msg, params object[] args)
  31. {
  32. Write(severity, msg + Environment.NewLine, args);
  33. }
  34. public static void WriteLine(Severity severity, string msg, params object[] args)
  35. {
  36. Write(severity, msg + Environment.NewLine, args);
  37. }
  38. public static void Write(Severity severity, string msg, params object[] args)
  39. {
  40. Write(m_colours[(int)severity], msg, args);
  41. }
  42. public static void Write(Color severity, string msg, params object[] args)
  43. {
  44. if (OnWrite == null)
  45. return;
  46. OnWrite(severity, msg, args);
  47. }
  48. public delegate void OutputFunction(Color severity, string msg, params object[] args);
  49. public static event OutputFunction OnWrite = null;
  50. }
  51. }