Advertisement
guitarplayer616

CraftOS 2.0

May 28th, 2015
679
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.09 KB | None | 0 0
  1. local w,h = term.getSize()
  2. term.setTextColor(colors.yellow)
  3. term.setBackgroundColor(colors.white)
  4. term.clear()
  5. term.setCursorPos(1,1)
  6. print("CraftOS 1.6")
  7. term.write(">  ")
  8. local on = nil
  9. local x,y = nil, nil
  10. local curPos = nil
  11. local str = ""
  12.  
  13. function inscribe(string,a,b,textcol,backcol)
  14.   if a and b then
  15.     term.setCursorPos(a,b)
  16.   end
  17.   if textcol then
  18.     term.setTextColor(textcol)
  19.   end
  20.   if backcol then
  21.     term.setBackgroundColor(backcol)
  22.   end
  23.   write(string)
  24. end
  25.  
  26. function blink(x,y)
  27.   x,y = nil,nil
  28.   if not on then
  29.     x,y = term.getCursorPos()
  30.     inscribe("|",x-1,y,colors.black)
  31.     write(string.rep(" ",w-x))
  32.     term.setCursorPos(x,y)
  33.     on = true
  34.   elseif on then
  35.     x,y = term.getCursorPos()
  36.     inscribe(" ",x-1,y,colors.black)
  37.     write(string.rep(" ",w-x))
  38.     term.setCursorPos(x,y)
  39.     on = nil
  40.   end
  41.   os.startTimer(.4)
  42. end
  43.  
  44. function scribe(string,textcol,backcol)
  45.   x,y = term.getCursorPos()
  46.   inscribe(string,x-1,y,textcol,backcol)
  47.   term.setCursorPos(x+1,y)
  48. end
  49.    
  50. function delete()
  51.   x,y = term.getCursorPos()
  52.   inscribe("  ",x-2,y)
  53.   term.setCursorPos(x-1,y)
  54. end
  55.  
  56. os.startTimer(.4)
  57.  
  58. while true do
  59.   local e = {os.pullEventRaw()}
  60.   if e[1] == "timer" and e[2] then
  61.     blink()
  62.   end
  63.   if e[1] == "terminate" then
  64.     inscribe("Terminated \n",_,_,colors.red)
  65.     inscribe("Goodbye \n",_,_,colors.yellow)
  66.     blink()
  67.     sleep(1)
  68.     term.clear()
  69.     os.shutdown()
  70.   end
  71.   if e[1] == "char" then
  72.     scribe(e[2])
  73.     if e[2] then
  74.       str = str..tostring(e[2])
  75.     end
  76.   end
  77.   curPosX,curPosY = term.getCursorPos()
  78.   if (e[1] == "key" and e[2] == 14) and (curPosX > 4 or curPosY < 2)  then
  79.     delete()
  80.     str = table.concat{str:sub(1,str:len()-1),"",str:sub(str:len()+1)}
  81.   end
  82.   if e[1] == "key" and e[2] == 28 then
  83.     x,y = term.getCursorPos()
  84.     inscribe(" ",x-1,y)
  85.     print(nil)
  86.     shell.run(str)
  87.     term.setTextColor(colors.yellow)
  88.     write(">  ")
  89.     term.setTextColor(colors.white)
  90.     str = ""
  91.   end
  92.   if e[1] == "key" and e[2] == 56 then
  93.     shell.run("pastebin run XAktVaSD")
  94.   end
  95. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement