Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local params = {...}
- local colorFile = params[1] .. ".col"
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setTextColor(colors.white)
- local color = {}
- local palette = {
- text = colors.black,
- background = colors.black,
- header = colors.black
- }
- function fileExists(filename)
- local file = fs.open(filename, "r")
- if file then
- file.close()
- return true
- end
- return false
- end
- local function loadColors ()
- local palette = {
- text = colors.black,
- background = colors.black,
- header = colors.black
- }
- local file = fs.open("/" .. colorFile, "r")
- if not file then
- error("Could not open " .. colorFile)
- end
- local index = 1
- repeat
- line = file.readLine()
- if line then
- if index == 1 then
- palette.text = tonumber(line)
- elseif index == 2 then
- palette.background = tonumber(line)
- elseif index == 3 then
- palette.header = tonumber(line)
- end
- index = index + 1
- end
- until line == nil
- file.close()
- return palette
- end
- local function saveColors (palette)
- local file = fs.open("/" .. colorFile, "w")
- file.writeLine(palette.text .. "")
- file.writeLine(palette.background .. "")
- file.writeLine(palette.header .. "")
- file.close()
- end
- local function setColor (mouseButton, colorIndex)
- if mouseButton == 1 then
- palette.text = colorIndex
- elseif mouseButton == 2 then
- palette.background = colorIndex
- elseif mouseButton == 3 then
- palette.header = colorIndex
- end
- end
- local function colorsChosen ()
- if not palette.header
- or not palette.background
- or not palette.text
- then
- return false
- end
- return true
- end
- local function colorText (backgroundColor)
- if backgroundColor == colors.white
- or backgroundColor == colors.yellow
- then
- term.setTextColor(colors.black)
- else
- term.setTextColor(colors.white)
- end
- end
- local function displayColors (palette)
- term.setCursorPos(10, #color + 1)
- term.setBackgroundColor(
- palette.text
- )
- colorText(palette.text)
- term.write("Text")
- term.setCursorPos(10, #color + 2)
- term.setBackgroundColor(
- palette.background
- )
- colorText(palette.background)
- term.write("Background")
- term.setCursorPos(10, #color + 3)
- term.setBackgroundColor(
- palette.header
- )
- colorText(palette.header)
- term.write("Header")
- end
- --Main program
- if not fileExists(colorFile) then
- local file = fs.open(colorFile, "w")
- for i = 1, 3 do
- file.writeLine(colors.black .. "")
- end
- file.close()
- end
- palette = loadColors()
- local index = 1
- for key, value in pairs(colors) do
- term.setCursorPos(1, index)
- if type(value) ~= "function" then
- color[index] = value
- if key == "white" or key == "yellow" then
- term.setTextColor(colors.black)
- else
- term.setTextColor(colors.white)
- end
- term.setBackgroundColor(value)
- term.write(key)
- index = index + 1
- end
- end
- repeat
- displayColors(palette)
- local event, button, x, y
- = os.pullEvent("mouse_click")
- if y <= #color then
- setColor(button, color[y])
- end
- until y > #color
- saveColors(palette)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.clear()
- displayColors(palette)
- term.setCursorPos(1, 1)
Advertisement
Add Comment
Please, Sign In to add comment