Guest User

coz_core

a guest
Jan 8th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.00 KB | None | 0 0
  1. local tX,tY,cX,cY
  2.  
  3. function getVersion()
  4.   ver = "0.1"
  5.   return ver
  6. end
  7.  
  8. -- BASIC FUNCTIONS
  9.  
  10. function clear(delay)
  11.   if delay == true then
  12.     os.sleep(1)
  13.   end
  14.   term.clear()
  15.   term.setCursorPos(1,1)
  16. end
  17.  
  18. function newLine(indent)
  19.   if indent == nil then
  20.     indent = 0
  21.   end
  22.  
  23.   cX,cY = term.getCursorPos()
  24.   term.setCursorPos(1+indent,cY+1)
  25. end
  26.  
  27. function cPrint(text,line)
  28.   if line == nil then
  29.     cX,cY = term.getCursorPos()
  30.     line = cY
  31.   end
  32.  
  33.   tX,tY = term.getSize()
  34.   term.setCursorPos( (tX/2) - (#text/2), line  )
  35.  
  36.   term.write(text)  
  37. end
  38.  
  39. -- END OF BASIC FUNCTIONS
  40.  
  41. function drawAlertBox()
  42.   tX,tY = term.getSize()
  43.   temp = (tY/2)-4
  44.  
  45.   term.setCursorPos(1,temp)  
  46.   for i=1,7 do
  47.     if i%7 == 0 or i%7 == 1 then
  48.       cPrint("*******************************") newLine()
  49.     else
  50.       cPrint("*                             *") newLine()
  51.     end
  52.   end
  53. end
  54.  
  55. function alertBox(info)
  56.   drawAlertBox()
  57.   term.setCursorPos(1,(tY/2)-2)
  58.   cPrint(info)  
  59.   term.setCursorPos(1,tY-1)
  60. end
  61.  
  62. -- FILE HANDLES
  63.  
  64. function addLinetoFile(text,file)
  65.   temp = {}
  66.     if not fs.exists(file) then
  67.       print("Creating file")
  68.       clear(true)
  69.       f = io.open(file,"w")
  70.       f:close()
  71.     end
  72.   f = io.open(file,"r")
  73.     if f == nil then
  74.       error("Failed to load")
  75.       return nil
  76.     end
  77.    
  78.     for line in f:lines() do
  79.       temp[#temp+1] = line
  80.     end
  81.   temp[#temp+1] = text
  82.   f:close()
  83.   f = fs.open(file,"w")
  84.     for i=1,#temp do
  85.       f.writeLine(temp[i])
  86.     end
  87.   f:close()
  88. end
  89.  
  90. function delLinefromFile(text,file)
  91.   temp = {}
  92.   f = io.open(file,"r")
  93.     if f == nil then
  94.       error("File not Found")
  95.       return nil
  96.     end
  97.    
  98.     for line in f:lines() do
  99.       if not(string.lower(line) == string.lower(text)) then
  100.         temp[#temp+1] = line
  101.       end
  102.     end
  103.   f:close()
  104.   f = fs.open(file,"w")
  105.     if f == nil then
  106.       return nil
  107.     end
  108.    
  109.     for i=1,#temp do
  110.       f.writeLine(temp[i])
  111.     end
  112.   f.close()
  113. end
Advertisement
Add Comment
Please, Sign In to add comment