Advertisement
mypal125

Untitled

May 22nd, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. -- CWCOS and its installer is licensed under the BSD 3-Clause License.
  2. -- Copyright (c) 2014 ClassCoder
  3. -- See the license at http://opensource.org/licenses/BSD-3-Clause.
  4.  
  5. -- CWCOS Kernel developers:
  6. -- ClassCoder
  7.  
  8. kernel = {}
  9.  
  10. -- We need the installer's centering, duh!
  11. -- Various functions with minor indentation modification
  12. -- http://www.computercraft.info/forums2/index.php?/topic/460-how-to-center-text/page__view__findpost__p__2948
  13. function kernel.centerText(text)
  14. local x,y = term.getSize()
  15. local x2,y2 = term.getCursorPos()
  16. term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
  17. write(text)
  18. end
  19. -- http://www.computercraft.info/forums2/index.php?/topic/460-how-to-center-text/page__view__findpost__p__70667
  20. -- Also added yplusminus, I needed to control that
  21. function kernel.centerTextXY(text, yplusminus)
  22. if yplusminus == nil then
  23. yplusminus = 0
  24. end
  25. local w, h = term.getSize()
  26. term.setCursorPos(math.floor(w / 2 - text:len() / 2 + .5), math.floor(h / 2 + .5) + yplusminus)
  27. io.write(text)
  28. end
  29.  
  30. -- And term clearing...
  31. -- Terminal clearers
  32. function kernel.clearTermWName(fg, bg, msg)
  33. kernel.colorTerm(fg, bg)
  34. term.clear()
  35. kernel.centerTextXY("CWCOS", 0)
  36. kernel.colorTerm(colors.lightBlue, colors.black)
  37. kernel.centerTextXY(msg, 1)
  38. local sizex,sizey = term.getSize()
  39. term.setCursorPos(1, 1)
  40. kernel.colorTerm(fg, bg)
  41. end
  42. function kernel.clearTerm()
  43. term.clear()
  44. term.setCursorPos(1, 1)
  45. end
  46. function kernel.resetTerm()
  47. kernel.colorTerm(colors.white, colors.black)
  48. kernel.clearTerm()
  49. term.setCursorPos(1, 1)
  50. end
  51. -- Terminal colorer
  52. function kernel.colorTerm(fg, bg)
  53. term.setTextColor(fg)
  54. term.setBackgroundColor(bg)
  55. end
  56. function kernel.shutdown()
  57. kernel.clearTermWName(colors.blue, colors.black, "Shutting down...")
  58. sleep(.75)
  59. os.shutdown()
  60. end
  61. function kernel.reboot()
  62. kernel.clearTermWName(colors.blue, colors.black, "Restarting...")
  63. sleep(.75)
  64. os.reboot()
  65. end
  66.  
  67. toInit = {
  68. ['kernel'] = kernel,
  69. }
  70.  
  71. kernel.clearTermWName(colors.blue, colors.black, "Booting...")
  72. print("[KERNEL] Kernel started")
  73. sleep(.5)
  74. os.run(toInit, "/bin/init")
  75. kernel.centerTextXY("Init crash", -1)
  76. kernel.centerTextXY("Collecting data", 0)
  77. kernel.centerTextXY("000%", 1)
  78. sleep(1)
  79. kernel.centerTextXY("025%", 1)
  80. sleep(1)
  81. kernel.centerTextXY("050%", 1)
  82. sleep(1)
  83. kernel.centerTextXY("075%", 1)
  84. sleep(1)
  85. kernel.centerTextXY("100%", 1)
  86. sleep(.5)
  87. os.shutdown()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement