SHARE
TWEET

Untitled

a guest Oct 18th, 2019 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local gpu = require("component").gpu
  2. local unicode = require("unicode")
  3. local length, width = gpu.getResolution()
  4.  
  5. local function setColorText(x, y, text)
  6.     if not x then
  7.         x = math.floor(length / 2 - unicode.len(text:gsub("%[%w+]", "")) / 2)
  8.     end
  9.  
  10.     local skip, skipLen = 0, 0
  11.  
  12.     for i = 1, unicode.len(text) do
  13.         if skip == 0 then
  14.             local symbol = unicode.sub(text, i, i)
  15.  
  16.             if symbol == "[" then
  17.                 local endLen = 0
  18.  
  19.                 for j = i, unicode.len(text) do
  20.                     if unicode.sub(text, j, j) == "]" then
  21.                         break
  22.                     end
  23.  
  24.                     endLen = endLen + 1
  25.                 end
  26.  
  27.                 gpu.setForeground(tonumber(unicode.sub(text, i + 1, i + endLen - 1)))
  28.                 skip, skipLen = endLen, skipLen + unicode.len(unicode.sub(text, i, endLen + i))
  29.             else
  30.                 gpu.set(x + i - skipLen - 1, y, symbol)
  31.             end
  32.         else
  33.             skip = skip - 1
  34.         end
  35.     end
  36. end
  37.  
  38. local text = "[0xffffff]Привет[0x000000]пока"
  39. setColorText(nil, 1, text)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top