Cakejoke

[CC] COS-CJE iox API

Dec 22nd, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.39 KB | None | 0 0
  1. local isAdvanced
  2.  
  3. local function init()
  4.     isAdvanced = term.isColor()
  5. end
  6.  
  7. function colorWrite(message, color)
  8.     init()
  9.     if not color then
  10.         color = colors.white
  11.     end
  12.     if isAdvanced then
  13.         term.setTextColor(color)
  14.     end
  15.     write(message)
  16.     if isAdvanced then
  17.         term.setTextColor(colors.white)
  18.     end
  19. end
  20.  
  21. function highlightWrite(message, color, doFillLine)
  22.     local whitespaces = ""
  23.     local posOfNewline
  24.     local doBreak = false
  25.     init()
  26.     if not color then
  27.         color = colors.black
  28.     end
  29.     if isAdvanced then
  30.         term.setBackgroundColor(color)
  31.     end
  32.     if doFillLine then
  33.         while true do
  34.             posOfNewline = message:find("\n")
  35.             if doBreak then
  36.                 break
  37.             end
  38.             if posOfNewline == nil then
  39.                 posOfNewline = message:len() + 1
  40.                 doBreak = true
  41.             end
  42.             for i = 1, term.getSize() - message:sub(1, posOfNewline - 1):len()
  43.                     % term.getSize() do
  44.                 whitespaces = whitespaces.." "
  45.             end
  46.             message = message:sub(1, posOfNewline - 1)..whitespaces..
  47.                     message:sub(posOfNewline + 1, message:len())
  48.         end
  49.     end
  50.     write(message)
  51.     if isAdvanced then
  52.         term.setBackgroundColor(colors.black)
  53.     end
  54. end
  55.  
  56. function colorWriteWithHighlight(message, textColor, highlightColor, doFillLine)
  57.     local whitespaces = ""
  58.     init()
  59.     if not textColor then
  60.         textColor = color.white
  61.     end
  62.     if not highlightColor then
  63.         highlightColor = colors.black
  64.     end
  65.     if isAdvanced then
  66.         term.setTextColor(textColor)
  67.         term.setBackgroundColor(highlightColor)
  68.     end
  69.     if doFillLine then
  70.         while true do
  71.             posOfNewline = message:find("\n")
  72.             if doBreak then
  73.                 break
  74.             end
  75.             if posOfNewline == nil then
  76.                 posOfNewline = message:len() + 1
  77.                 doBreak = true
  78.             end
  79.             for i = 1, term.getSize() - message:sub(1, posOfNewline - 1):len()
  80.                     % term.getSize() do
  81.                 whitespaces = whitespaces.." "
  82.             end
  83.             message = message:sub(1, posOfNewline - 1)..whitespaces..
  84.                     message:sub(posOfNewline + 1, message:len())
  85.         end
  86.     end
  87.     write(message..whitespaces)
  88.     if isAdvanced then
  89.         term.setTextColor(colors.white)
  90.         term.setBackgroundColor(colors.black)
  91.     end
  92. end
  93.  
  94. function colorPrint(message, color)
  95.     colorWrite(message.."\n", color)
  96. end
  97.  
  98. function highlightPrint(message, color, doFillLine)
  99.     highlightWrite(message.."\n", color, doFillLine)
  100. end
  101.  
  102. function colorPrintWithHighlight(message, textColor, highlightColor, doFillLine)
  103.     colorWriteWithHighlight(message.."\n", textColor, highlightColor, doFillLine)
  104. end
Advertisement
Add Comment
Please, Sign In to add comment