Advertisement
visiongaming43

colorLib

Jun 11th, 2022
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. ACCEPTABLE_COLORS = {
  2. "colors.white",
  3. "colors.orange",
  4. "colors.magenta",
  5. "colors.lightBlue",
  6. "colors.yellow",
  7. "colors.lime",
  8. "colors.pink",
  9. "colors.gray",
  10. "colors.lightGray",
  11. "colors.cyan",
  12. "colors.purple",
  13. "colors.blue",
  14. "colors.brown",
  15. "colors.green",
  16. "colors.red",
  17. "colors.black"
  18. }
  19.  
  20. local expect = require("cc.expect")
  21. local exp, field, range = expect.expect, expect.field, expect.range
  22.  
  23. function printColor(text, color)
  24. exp(1, text, "string")
  25. exp(1, color, "string")
  26. for index, value in ipairs(ACCEPTABLE_COLORS) do
  27. if (color == value) then break end
  28. if (color ~= value and index == #ACCEPTABLE_COLORS) then
  29. print(text)
  30. end
  31. end
  32. term.setTextColor(color)
  33. print(text)
  34. term.setTextColor("colors.white")
  35. end
  36.  
  37. function writeColor(text, color)
  38. exp(1, text, "string")
  39. exp(1, color, "string")
  40. for index, value in ipairs(ACCEPTABLE_COLORS) do
  41. if (color == value) then break end
  42. if (color ~= value and index == #ACCEPTABLE_COLORS) then
  43. write(text)
  44. end
  45. end
  46. term.setTextColor(color)
  47. write(text)
  48. term.setTextColor("colors.white")
  49. end
  50.  
  51. return { printColor = printColor, writeColor = writeColor }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement