Advertisement
guitarplayer616

Emulate

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