minilog.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/usr/bin/env python3
  2. #
  3. # Just some simple print-to-stderr logging.
  4. #
  5. # Written by: Andrew <https://www.andrewyu.org>
  6. #
  7. # This is free and unencumbered software released into the public
  8. # domain.
  9. #
  10. # Anyone is free to copy, modify, publish, use, compile, sell, or
  11. # distribute this software, either in source code form or as a compiled
  12. # binary, for any purpose, commercial or non-commercial, and by any
  13. # means.
  14. #
  15. # In jurisdictions that recognize copyright laws, the author or authors
  16. # of this software dedicate any and all copyright interest in the
  17. # software to the public domain. We make this dedication for the benefit
  18. # of the public at large and to the detriment of our heirs and
  19. # successors. We intend this dedication to be an overt act of
  20. # relinquishment in perpetuity of all present and future rights to this
  21. # software under copyright law.
  22. #
  23. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  26. # IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  27. # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  28. # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  29. # OTHER DEALINGS IN THE SOFTWARE.
  30. import sys
  31. class textStyle:
  32. reset = "\033[0m"
  33. fgBlack = "\033[30m"
  34. fgBrightBlack = "\033[30;1m"
  35. bgBlack = "\033[40m"
  36. bgBrightBlack = "\033[40;1m"
  37. fgRed = "\033[31m"
  38. fgBrightRed = "\033[31;1m"
  39. bgRed = "\033[41m"
  40. bgBrightRed = "\033[41;1m"
  41. fgGreen = "\033[32m"
  42. fgBrightGreen = "\033[32;1m"
  43. bgGreen = "\033[42m"
  44. bgBrightGreen = "\033[42;1m"
  45. fgYellow = "\033[33m"
  46. fgBrightYellow = "\033[33;1m"
  47. bgYellow = "\033[43m"
  48. bgBrightYellow = "\033[43;1m"
  49. fgBlue = "\033[34m"
  50. fgBrightBlue = "\033[34;1m"
  51. bgBlue = "\033[44m"
  52. bgBrightBlue = "\033[44;1m"
  53. fgMagenta = "\033[35m"
  54. fgBrightMagenta = "\033[35;1m"
  55. bgMagenta = "\033[45m"
  56. bgBrightMagenta = "\033[45;1m"
  57. fgCyan = "\033[36m"
  58. fgBrightCyan = "\033[36;1m"
  59. bgCyan = "\033[46m"
  60. bgBrightCyan = "\033[46;1m"
  61. fgWhite = "\033[37m"
  62. fgBrightWhite = "\033[37;1m"
  63. bgWhite = "\033[47m"
  64. bgBrightWhite = "\033[47;1m"
  65. def parser(s: str) -> None:
  66. print(
  67. textStyle.reset + "[P] " + s + textStyle.reset, file=sys.stdout
  68. )
  69. def debug(s: str) -> None:
  70. print(
  71. textStyle.fgBrightWhite + "[D] " + s + textStyle.reset,
  72. file=sys.stdout,
  73. )
  74. def info(s: str) -> None:
  75. print(
  76. textStyle.fgGreen + "[I] " + s + textStyle.reset,
  77. file=sys.stdout,
  78. )
  79. def note(s: str) -> None:
  80. print(
  81. textStyle.fgBrightBlue + "[N] " + s + textStyle.reset,
  82. file=sys.stdout,
  83. )
  84. def caution(s: str) -> None:
  85. print(
  86. textStyle.fgBrightYellow + "[C] " + s + textStyle.reset,
  87. file=sys.stdout,
  88. )
  89. def warning(s: str) -> None:
  90. print(
  91. textStyle.fgYellow + "[W] " + s + textStyle.reset,
  92. file=sys.stdout,
  93. )
  94. def error(s: str) -> None:
  95. print(
  96. textStyle.fgRed + "[E] " + s + textStyle.reset, file=sys.stdout
  97. )