local gpu = require("component").gpu local unicode = require("unicode") local length, width = gpu.getResolution() local function setColorText(x, y, text) if not x then x = math.floor(length / 2 - unicode.len(text:gsub("%[%w+]", "")) / 2) end local skip, skipLen = 0, 0 for i = 1, unicode.len(text) do if skip == 0 then local symbol = unicode.sub(text, i, i) if symbol == "[" then local endLen = 0 for j = i, unicode.len(text) do if unicode.sub(text, j, j) == "]" then break end endLen = endLen + 1 end gpu.setForeground(tonumber(unicode.sub(text, i + 1, i + endLen - 1))) skip, skipLen = endLen, skipLen + unicode.len(unicode.sub(text, i, endLen + i)) else gpu.set(x + i - skipLen - 1, y, symbol) end else skip = skip - 1 end end end local text = "[0xffffff]Привет[0x000000]пока" setColorText(nil, 1, text)