Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- colorAPI.lua
- local colors = {
- ["0"] = colors.black,
- ["1"] = colors.blue,
- ["2"] = colors.green,
- ["3"] = colors.cyan,
- ["4"] = colors.red,
- ["5"] = colors.purple,
- ["6"] = colors.orange,
- ["7"] = colors.lightGray,
- ["8"] = colors.gray,
- ["9"] = colors.lightBlue,
- ["a"] = colors.lime,
- ["b"] = colors.lightBlue,
- ["c"] = colors.red,
- ["d"] = colors.magenta,
- ["e"] = colors.yellow,
- ["f"] = colors.white,
- }
- local function msg(text, monitor)
- local x, y = monitor.getCursorPos()
- local originalBgColor = monitor.getBackgroundColor()
- local originalTextColor = monitor.getTextColor()
- local i = 1
- while i <= #text do
- local char = text:sub(i, i)
- if char == "&" then
- local nextChar = text:sub(i + 1, i + 1)
- if nextChar == "&" then
- i = i + 2
- local colorCode = text:sub(i + 1, i + 1)
- if colors[colorCode] then
- monitor.setBackgroundColor(colors[colorCode])
- end
- i = i + 1
- else
- i = i + 1
- local colorCode = text:sub(i, i)
- if colors[colorCode] then
- monitor.setTextColor(colors[colorCode])
- end
- end
- else
- monitor.write(char)
- end
- i = i + 1
- end
- monitor.setTextColor(originalTextColor)
- monitor.setBackgroundColor(originalBgColor)
- end
- return {
- msg = msg
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement