Advertisement
pfgpastebin

CLI cprint REUPLOAD

Feb 6th, 2015
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.34 KB | None | 0 0
  1. --Sorry creator of cprint, had to re upload due to problems with the CC website
  2. -- -pfg
  3.  
  4.  
  5. -- Do auto update?
  6. local auto = false
  7.  
  8. --[[
  9.     ###INFO###
  10.     * Language
  11.        Lua (ComputerCraft)
  12.        
  13.     * Version
  14.        1.3
  15.        
  16.     * Status
  17.        Working, not closed.
  18. ]]--
  19.  
  20. --[[
  21.     cPrint API by Jesusthekiller
  22.     This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
  23.     More info: http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_US
  24. ]]--
  25.  
  26. --[[
  27.     Big thanks to theorginalbit for help with cCode and toCode!
  28. ]]--
  29.  
  30. --[[
  31.     Version log:
  32.     1.0:
  33.      * Initial release
  34.    
  35.     1.1:
  36.      * Added cwrite
  37.      * Added update
  38.      * cprint now adds "\n" to the end of the line
  39.      * Improved cCode
  40.      * Improved toCode
  41.      * Auto updater
  42.      
  43.     1.2:
  44.      * Added non-advanced computer support
  45.      * Bugfixes
  46.  
  47.     1.3:
  48.      * Even better non-advanced computer support
  49. ]]--
  50.  
  51. local DO_NOT_TOUCH = 5
  52.  
  53. -- Updater func:
  54.  
  55. function update()
  56.     if not http then
  57.         error("HTTP API required!")
  58.     end
  59.    
  60.     cprint("&5Checking for &4cprint &5update...")
  61.    
  62.     local v = http.get("http://mindblow.no-ip.org/code/cprint/ver")
  63.    
  64.     if v == nil then
  65.         error("nil response from update server! Check your internet connection!")
  66.     end
  67.    
  68.     if tonumber(v.readLine()) <= DO_NOT_TOUCH then
  69.         cprint("&5No new updates!")
  70.         return false
  71.     end
  72.    
  73.     -- Install cPrint
  74.    
  75.     cprint("&5Downloading &4cPrint&5...")
  76.    
  77.     local f = http.get(v.readLine())
  78.    
  79.     cprint("&5Installing &4cPrint&5 as &4cprint &5in main directory...")
  80.    
  81.     local e = fs.open("cprint", "w") -- API Folder
  82.    
  83.     e.write(f.readAll())
  84.    
  85.     e.close()
  86.     f.close()
  87.    
  88.     -- Install palette
  89.    
  90.     cprint("&5Downloading &4Palette&5...")
  91.    
  92.     local f = http.get(v.readLine())
  93.    
  94.     v.close()
  95.    
  96.     cprint("&5Installing &4Palette&5 as &4palette &5in main directory...")
  97.    
  98.     local e = fs.open("palette", "w") -- API Folder
  99.    
  100.     e.write(f.readAll())
  101.    
  102.     e.close()
  103.     f.close()
  104.    
  105.     v.close()
  106.     print("Done!")
  107.     return true
  108. end
  109.  
  110. function sc(x, y)
  111.     term.setCursorPos(x, y)
  112. end
  113.  
  114. function clear(move)
  115.     sb(colors.black)
  116.     term.clear()
  117.     if move ~= false then sc(1,1) end
  118. end
  119.  
  120. function sb(color)
  121.     term.setBackgroundColor(color)
  122. end
  123.  
  124. function st(color)
  125.     term.setTextColor(color)
  126. end
  127.  
  128. function cCode(h)
  129.     if term.isColor() and term.isColor then
  130.         return 2 ^ (tonumber(h, 16) or 0)
  131.     else
  132.         if h == "f" then
  133.             return colors.black
  134.         else
  135.             return colors.white
  136.         end
  137.     end
  138. end
  139.  
  140. function toCode(n)
  141.     return string.format('%x', n)
  142. end
  143.  
  144. function cwrite(text)
  145.     text = tostring(text)
  146.    
  147.     local i = 0
  148.     while true  do
  149.         i = i + 1
  150.         if i > #text then break end
  151.        
  152.         local c = text:sub(i, i)
  153.  
  154.         if c == "\\" then
  155.             if text:sub(i+1, i+1) == "&" then
  156.                 write("&")
  157.                 i = i + 1
  158.             elseif text:sub(i+1, i+1) == "+" then
  159.                 write("+")
  160.                 i = i + 1
  161.             else
  162.                 write(c)
  163.             end
  164.         elseif c == "&" then
  165.             st(cCode(text:sub(i+1, i+1)))
  166.             i = i + 1
  167.         elseif c == "+" then
  168.             sb(cCode(text:sub(i+1, i+1)))
  169.             i = i + 1
  170.         else
  171.             write(c)
  172.         end
  173.     end
  174.    
  175.     return
  176. end
  177.  
  178. function cprint(text)
  179.     return cwrite(tostring(text).."\n")
  180. end
  181.  
  182. if auto then update() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement