boot.lua 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. --The handled APIS
  2. Handled = ...
  3. --Make peripherals as global
  4. for k,v in pairs(Handled) do
  5. _G[k] = v
  6. end
  7. --A useful DiskOS function
  8. function input()
  9. local t = ""
  10. local fw, fh = GPU.fontSize()
  11. local blink = false
  12. local blinktimer = 0
  13. local blinktime = 0.5
  14. local function drawblink()
  15. local cx,cy,c = GPU.printCursor()
  16. GPU.rect(cx*(fw+1)+1,blink and cy*(fh+2)+1 or cy*(fh+2),fw+1,blink and fh or fh+4,false,blink and 4 or c) --The blink
  17. end
  18. for event,a,b,c,d,e,f in CPU.pullEvent do
  19. if event == "textinput" then
  20. t = t .. a
  21. GPU.print(a,false)
  22. elseif event == "keypressed" then
  23. if a == "backspace" then
  24. blink = false; drawblink()
  25. if t:len() > 0 then GPU.printBackspace() end
  26. blink = true; drawblink()
  27. t = t:sub(0,-2)
  28. elseif a == "return" then
  29. blink = false; drawblink()
  30. return t --Return the text
  31. elseif a == "escape" then
  32. return false --User canceled text input.
  33. elseif a == "v" and Keyboard.isKDown("lctrl","rctrl") then
  34. CPU.triggerEvent("textinput",CPU.clipboard())
  35. end
  36. elseif event == "touchpressed" then
  37. Keyboard.textinput(true)
  38. elseif event == "update" then --Blink
  39. blinktimer = blinktimer + a
  40. if blinktimer > blinktime then
  41. blinktimer = blinktimer % blinktime
  42. blink = not blink
  43. drawblink()
  44. end
  45. end
  46. end
  47. end
  48. --Start the interpreter
  49. CPU.sleep(1)
  50. Keyboard.textinput(true)
  51. GPU.print(_VERSION.." Interpreter - PoorOS V1.0")
  52. CPU.sleep(1)
  53. GPU.pushColor()
  54. while true do
  55. GPU.color(7) GPU.print("> ",false)
  56. local code = input(); GPU.print("")
  57. if code then
  58. local chunk, err = loadstring(code)
  59. if not chunk then
  60. GPU.color(8) GPU.print("C-ERR: "..tostring(err))
  61. else
  62. GPU.popColor()
  63. local ok, err = pcall(chunk)
  64. GPU.pushColor()
  65. if not ok then
  66. GPU.color(8) GPU.print("R-ERR: "..tostring(err))
  67. else
  68. GPU.print("")
  69. end
  70. end
  71. end
  72. end