Trystan_C_C

Color API for Shell

Nov 18th, 2012
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.52 KB | None | 0 0
  1. local textColorBuffer = colors.white -- The color that is currently being used for the default text color.
  2. local backgroundColorBuffer = colors.black -- The color that is currently being used for the default background color.
  3. -- Set the text and background colors to their defaults.
  4. term.setTextColor(textColorBuffer)
  5. term.setBackgroundColor(backgroundColorBuffer)
  6.  
  7. -- Sets the  cursor to the given position and the text and background colors if provided, then
  8. -- writes the text to the screen.
  9. function positionAndWrite(xPos, yPos, text, textColor, backgroundColor)
  10.       term.setCursorPos(xPos, yPos)
  11.       term.setTextColor(isColorValid(textColor) or textColorBuffer)
  12.       term.setBackgroundColor(isColorValid(backgroundColor) or backgroundColorBuffer)
  13.       term.write(text)
  14. end
  15.  
  16. -- Writes the given text to the screen with the given text and background colors.
  17. function writeWithColor(text, textColor, backgroundColor)
  18.       term.setTextColor(isColorValid(textColor) or textColorBuffer)
  19.       term.setBackgroundColor(isColorValid(backgroundColor) or backgroundColorBuffer)
  20.       term.write(text)
  21. end
  22.  
  23. -- Returns the color given if it is valid, and nil if it was false.
  24. function isColorValid(color)
  25.       for index, colorVal in pairs(colors) do
  26.             if colorVal == color then
  27.                   return color
  28.             end
  29.       end
  30.      
  31.       return nil
  32. end
  33.  
  34. -- Returns the current text and background colors in the buffer.
  35. function getBufferColors()
  36.       return textColorBuffer, backgroundColorBuffer
  37. end
Advertisement
Add Comment
Please, Sign In to add comment