xXm0dzXx

Untitled

Nov 29th, 2012
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.00 KB | None | 0 0
  1. local osCode = [[
  2. local windows = {}
  3. local screenData = {}
  4. local screenLine = {}
  5. local clipboard = ""
  6. local oldSize = term.getSize
  7. local oldClear = term.clear
  8. local currentColor = colors.white
  9. local currentBGColor = colors.black
  10.  
  11. term.forceCursorPos = term.setCursorPos
  12. oldClearLine = term.clearLine
  13. oldWrite = term.write
  14. oldSetColour = term.setTextColour
  15. oldSetBGColour = term.setBackgroundColour
  16. oldScroll = term.scroll
  17.  
  18. fixScreenData = function()
  19. local sD = screenData
  20.  
  21. screenLine = {}
  22. screenData = {}
  23. for i,v in pairs(sD) do
  24. screenData[ #screenData+1 ] = v
  25.  
  26. local currentLine = screenLine[ y ]
  27. if type(screenLine[ y ]) ~= "table" then
  28. screenLine[ y ] = {}
  29. end
  30.  
  31. screenLine[ y ][#currentLine+1] = SCD
  32. end
  33. end
  34.  
  35. writeScreenData = function()
  36. local x,y = term.getCursorPos()
  37. oldClear()
  38. oldColor = currentColor
  39. oldBG = currentBGColor
  40.  
  41. for i=1,#screenData do
  42. local info = screenData[i]
  43. term.setCursorPos( info["X"], info["Y"] )
  44. term.setBackgroundColour( info["BG_Color"] )
  45. term.setTextColour( info["TXT_Color"] )
  46.  
  47. write( info["Text"] )
  48. end
  49.  
  50. term.setTextColour( oldColor )
  51. term.setBackgroundColour( oldBG )
  52. term.setCursorPos( x, y )
  53. end
  54.  
  55. term.setTextColour = function( color )
  56. currentColor = color
  57. return oldSetColour( color )
  58. end
  59.  
  60. term.setBackgroundColor = function( color )
  61. currentBGColor = color
  62. return oldSetBGColour( color )
  63. end
  64.  
  65. term.paste = function()
  66. return os.queueEvent( "char", clipboard )
  67. end
  68.  
  69. term.clear = function()
  70. screenData = {}
  71. screenLine = {}
  72. return oldClear()
  73. end
  74.  
  75. term.clearLine = function()
  76. local x,y = term.getCursorPos
  77. local lineExists = screenLine[y]
  78. if lineExists then
  79. for i=1,#lineExists do
  80. textData = lineExists[i]
  81. if textData then
  82. screenData[ textData ] = nil
  83. end
  84. end
  85. fixScreenData()
  86. end
  87.  
  88. return oldClearLine()
  89. end
  90.  
  91. term.write = function( text )
  92. local x,y = term.getCursorPos()
  93. SCD = #screenData+1
  94. screenData[ SCD ] = {
  95. ["Text"] = text,
  96. ["TXT_Color"] = currentColor,
  97. ["BG_Color"] = currentBGColor,
  98. ["X"] = x,
  99. ["Y"] = y,
  100. }
  101. local currentLine = screenLine[ y ]
  102. if type(screenLine[ y ]) ~= "table" then
  103. screenLine[ y ] = {}
  104. currentLine = screenLine[ y ]
  105. end
  106.  
  107. screenLine[ y ][#currentLine+1] = SCD
  108.  
  109. return oldWrite( text )
  110. end
  111.  
  112. term.copy = function( text )
  113. clipboard = text
  114. end
  115.  
  116. term.getClipboard = function()
  117. return clipboard
  118. end
  119.  
  120. term.getWindows = function()
  121. return windows
  122. end
  123.  
  124. read = function( _sReplaceChar, _tHistory )
  125. term.setCursorBlink( true )
  126.  
  127. local oldMenu = false
  128. local hasMenu = false
  129. local cStart = 0
  130. local cEnd = 0
  131. local sLine = ""
  132. local nHistoryPos = nil
  133. local nPos = 0
  134. if _sReplaceChar then
  135. _sReplaceChar = string.sub( _sReplaceChar, 1, 1 )
  136. end
  137.  
  138. local w, h = term.getSize()
  139. local sx, sy = term.getCursorPos()
  140.  
  141. local function dropdown( x, y )
  142. prevtc = currentColor
  143. prevbc = currentBGColor
  144. for i=1,3 do
  145. term.setCursorPos(x,y+i-1)
  146. term.setBackgroundColour( colors.lightGray )
  147. oldWrite(" ")
  148. end
  149.  
  150. term.setCursorPos( x, y )
  151.  
  152. if cStart ~= 0 and cEnd ~= 0 then
  153. term.setTextColour( colors.gray )
  154. else
  155. term.setTextColour( colors.white )
  156. end
  157. oldWrite(" Copy ")
  158.  
  159. term.setCursorPos( x, y+1 )
  160.  
  161. if clipboard ~= "" then
  162. term.setTextColour( colors.gray )
  163. else
  164. term.setTextColour( colors.white )
  165. end
  166. oldWrite(" Paste ")
  167.  
  168. term.setCursorPos( x, y+2 )
  169.  
  170. term.setTextColour( colors.gray )
  171. oldWrite(" Explorer")
  172.  
  173. term.setTextColour( prevtc )
  174. term.setBackgroundColour( prevbc )
  175. end
  176.  
  177. local function redraw( _sCustomReplaceChar )
  178. local nScroll = 0
  179. if sx + nPos >= w then
  180. nScroll = (sx + nPos) - w
  181. end
  182.  
  183. term.setCursorPos( sx, sy )
  184. local sReplace = _sCustomReplaceChar or _sReplaceChar
  185. if sReplace then
  186. sText = string.rep(sReplace, string.len(sLine) - nScroll)
  187. else
  188. sText = string.sub( sLine, nScroll + 1 )
  189. end
  190.  
  191. if cStart ~= 0 and cEnd ~= 0 then
  192. local sText1 = string.sub( sText, 1, cStart-1 )
  193. local sHigh = string.sub( sText, cStart, cEnd )
  194. local sText2 = string.sub( sText, cEnd+1, #sText )
  195. if sText1 then
  196. write( sText1 )
  197. end
  198. term.setBackgroundColour( colors.blue )
  199. if sHigh then
  200. write( sHigh )
  201. end
  202. term.setBackgroundColour( currentBGColor )
  203. if sText2 then
  204. write( sText2 )
  205. end
  206. else
  207. write( sText )
  208. end
  209.  
  210. if oldMenu ~= hasMenu and oldMenu == true then
  211. writeScreenData()
  212. end
  213.  
  214. term.setCursorPos( sx + nPos - nScroll, sy )
  215. oldMenu = hasMenu
  216. end
  217.  
  218. local dragTimer = false
  219. while true do
  220. local sEvent, param, key, p2 = os.pullEvent()
  221. if sEvent == "char" then
  222. sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 )
  223. nPos = nPos + 1
  224. redraw()
  225.  
  226. elseif sEvent == "mouse_click" and p2 == sy then
  227. if param == 1 then
  228. cStart = 0
  229. cEnd = 0
  230. hasMenu = false
  231. redraw()
  232. elseif param == 2 then
  233. dropdown( key, p2 )
  234. end
  235.  
  236. elseif sEvent == "mouse_drag" and param == 1 then
  237. local p1 = key
  238. local cPos = p1-sx+1
  239.  
  240. if cPos > 0 then
  241. if dragTimer == false then
  242. if p2 == sy then
  243. cStart = cPos
  244. cEnd = cPos --I repeated code D: *Shoots myself*
  245. dragTimer = os.startTimer(0.3)--<+---^
  246. end-- |
  247. else-- |
  248. cEnd = cPos-- |
  249. dragTimer = os.startTimer(0.3)-- <-+
  250. end
  251.  
  252. end
  253. redraw()
  254.  
  255. elseif sEvent == "timer" then
  256. if param == dragTimer then
  257. dragTimer = false
  258. end
  259.  
  260. elseif sEvent == "key" then
  261. if param == keys.enter then
  262. -- Enter
  263. break
  264.  
  265. elseif param == keys.left then
  266. -- Left
  267. if nPos > 0 then
  268. nPos = nPos - 1
  269. redraw()
  270. end
  271.  
  272. elseif param == keys.right then
  273. -- Right
  274. if nPos < string.len(sLine) then
  275. nPos = nPos + 1
  276. redraw()
  277. end
  278.  
  279. elseif param == keys.up or param == keys.down then
  280. -- Up or down
  281. if _tHistory then
  282. redraw(" ");
  283. if param == keys.up then
  284. -- Up
  285. if nHistoryPos == nil then
  286. if #_tHistory > 0 then
  287. nHistoryPos = #_tHistory
  288. end
  289. elseif nHistoryPos > 1 then
  290. nHistoryPos = nHistoryPos - 1
  291. end
  292. else
  293. -- Down
  294. if nHistoryPos == #_tHistory then
  295. nHistoryPos = nil
  296. elseif nHistoryPos ~= nil then
  297. nHistoryPos = nHistoryPos + 1
  298. end
  299. end
  300.  
  301. if nHistoryPos then
  302. sLine = _tHistory[nHistoryPos]
  303. nPos = string.len( sLine )
  304. else
  305. sLine = ""
  306. nPos = 0
  307. end
  308. redraw()
  309. end
  310. elseif param == keys.backspace then
  311. -- Backspace
  312. if nPos > 0 then
  313. redraw(" ");
  314. sLine = string.sub( sLine, 1, nPos - 1 ) .. string.sub( sLine, nPos + 1 )
  315. nPos = nPos - 1
  316. redraw()
  317. end
  318. elseif param == keys.home then
  319. -- Home
  320. nPos = 0
  321. redraw()
  322. elseif param == keys.delete then
  323. if nPos < string.len(sLine) then
  324. redraw(" ");
  325. sLine = string.sub( sLine, 1, nPos ) .. string.sub( sLine, nPos + 2 )
  326. redraw()
  327. end
  328. elseif param == keys["end"] then
  329. -- End
  330. nPos = string.len(sLine)
  331. redraw()
  332. end
  333. end
  334. end
  335.  
  336. cStart = 0
  337. cEnd = 0
  338. redraw()
  339.  
  340. term.setCursorBlink( false )
  341. term.setCursorPos( w + 1, sy )
  342. print()
  343.  
  344. return sLine
  345. end
  346.  
  347. local x,y = term.getSize()
  348.  
  349. local function cPrint( txt, color, isMenu ) --Version 2.1 of cPrint
  350. local function printC( text )
  351. x2,y2 = term.getCursorPos()
  352. term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
  353. oldColz = currentColor
  354. if isMenu then
  355. term.setTextColour( colors.orange )
  356. write("[ ")
  357. end
  358.  
  359. if color then
  360. term.setTextColour( color )
  361. end
  362. write(text.. "\n")
  363.  
  364. if isMenu then
  365. term.setTextColour( colors.orange )
  366. write(" ]")
  367. end
  368.  
  369. term.setTextColour( oldColz )
  370. end
  371.  
  372. if type(txt) == "string" then
  373. printC( txt )
  374. elseif type(txt) == "table" then
  375. for i=1,#txt do
  376. printC( txt[i] )
  377. end
  378. end
  379. end
  380.  
  381. local drawingBoard = {
  382. ["A"] = colors.white,
  383. ["B"] = colors.orange,
  384. ["C"] = colors.magenta,
  385. ["D"] = colors.lightBlue,
  386. ["E"] = colors.yellow,
  387. ["F"] = colors.lime,
  388. ["G"] = colors.pink,
  389. ["H"] = colors.gray,
  390. ["I"] = colors.lightGray,
  391. ["J"] = colors.cyan,
  392. ["K"] = colors.purple,
  393. ["L"] = colors.blue,
  394. ["M"] = colors.brown,
  395. ["N"] = colors.green,
  396. ["O"] = colors.red,
  397. ["P"] = colors.black,
  398. }
  399.  
  400. local function advWrite( pos1, pos2, str )
  401. for i=1,#str do
  402. local symb = drawingBoard[ string.sub( str, i, i) ]
  403. term.setCursorPos( pos1 + (i-1) , pos2 )
  404. if symb then
  405. term.setBackgroundColour( symb )
  406. write(" ")
  407. end
  408. end
  409. end
  410.  
  411. local function setBG( col, colz )
  412. term.setBackgroundColour( col )
  413. term.clear()
  414. term.setCursorPos(1,1)
  415. term.setTextColour( colz )
  416. end
  417.  
  418. local function getLines( path )
  419. local tLines = {}
  420. local file = fs.open( path, "r" )
  421. if file then
  422. line = file.readLine()
  423. while line do
  424. tLines[ #tLines+1 ] = line
  425. line = file.readLine()
  426. end
  427. file.close()
  428. end
  429.  
  430. return tLines
  431. end
  432.  
  433. local function drawGUI()
  434. setBG( colors.black, colors.white )
  435. cPrint( "NeXoS 3.0" )
  436. write( string.rep( "-", x ) )
  437. term.setCursorPos(1,y)
  438. write("Login (Logged in as guest)")
  439. term.setCursorPos(1,y-1)
  440. write( string.rep( "-", x ) )
  441. term.setCursorPos(1,4)
  442. end
  443.  
  444. local selection = 1
  445. local menu = {
  446. [1] = {
  447. ["Text"] = "Exit",
  448. ["Color"] = colors.red,
  449. ["Function"] = error()
  450. }, --Keep at bottom
  451. }
  452.  
  453. drawGUI()
  454. local clock_ = os.startTimer( 0.5 )
  455. while true do
  456. for i=1,#menu do
  457. local sText = menu[i]["Text"]
  458. if menu[i]["Color"] ~= nil then
  459. sColor = menu[i]["Color"]
  460. else
  461. sColor = colors.white
  462. end
  463.  
  464. local isMenu = false
  465. if selection == i then
  466. isMenu = true
  467. end
  468.  
  469. term.clearLine()
  470. cPrint( sText, sColor, isMenu )
  471. print()
  472. end
  473.  
  474. local event, key = os.pullEvent()
  475. if event == "timer" then
  476. if key == clock_ then
  477. local time_ = textutils.formatTime( os.time() )
  478. term.setCursorPos( x-#(time_)+1, y )
  479. write( time_ )
  480. clock_ = os.startTimer( 0.5 )
  481. end
  482. elseif event == "key" then
  483. if key == keys.up then
  484. if selection ~= 1 then
  485. selection = selection -1
  486. end
  487. elseif key == keys.down then
  488. if selection ~= #menu then
  489. selection = selection +1
  490. end
  491. end
  492. end
  493. end
  494.  
  495. while true do
  496. end
  497. --]]
  498.  
  499. local x,y = term.getSize()
  500.  
  501. local function cPrint( txt ) --Version 2.0 of cPrint
  502. local function printC( text )
  503. x2,y2 = term.getCursorPos()
  504. term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
  505. write(text.. "\n")
  506. end
  507.  
  508. if type(txt) == "string" then
  509. printC( txt )
  510. elseif type(txt) == "table" then
  511. for i=1,#txt do
  512. printC( txt[i] )
  513. end
  514. end
  515. end
  516.  
  517. if fs.exists(".osCache") and fs.isDir(".osCache") then
  518. fs.delete(".osCache/main")
  519. file = fs.open(".osCache/main","w")
  520. file.write( osCode )
  521. file.close()
  522.  
  523. local function BSoD( _error )
  524. term.setBackgroundColour( colors.blue )
  525. term.clear()
  526. term.setCursorPos(1,4)
  527. term.setBackgroundColour( colors.white )
  528. term.setTextColour( colors.blue )
  529. cPrint(" ERROR ")
  530. term.setTextColour( colors.white )
  531. term.setBackgroundColour( colors.blue )
  532. print()
  533.  
  534. cPrint( "Failed to run OS: " .._error )
  535. print()
  536. cPrint( "Press any key to continue" )
  537. repeat
  538. local _, key = os.pullEvent( "key" )
  539. until key ~= 1
  540. term.setBackgroundColour( colors.black )
  541. end
  542.  
  543. local result = shell.run( ".osCache/main" )
  544. if type(result) ~= "boolean" then
  545. BSoD( result )
  546. end
  547. else
  548. term.clear()
  549. term.setCursorPos(1,3)
  550. cPrint("Installing OS")
  551. write("+" ..string.rep( "-", x-2 ).. "+")
  552. term.setCursorPos(1,5)
  553. write("|")
  554. term.setCursorPos(x,5)
  555. write("|")
  556. term.setCursorPos(1,6)
  557. write("+" ..string.rep( "-", x-2 ).. "+")
  558. print("\n")
  559. cPrint("Status")
  560. local _,statusPos = term.getCursorPos()
  561. local progress = 0
  562.  
  563. function addLoading( status )
  564. progress = progress +1
  565.  
  566. term.setCursorPos(1+progress,5)
  567. term.setBackgroundColour( colors.blue )
  568. write(" ")
  569. term.setBackgroundColour( colors.black )
  570.  
  571. if status then
  572. term.setCursorPos(1,statusPos)
  573. term.clearLine()
  574. cPrint( status )
  575. end
  576.  
  577. sleep(0)
  578. end
  579.  
  580. addLoading( "Generating API" )
  581. addLoading( "Removing Directories" )
  582. fs.delete( ".osCache" )
  583. addLoading( "Creating Directories" )
  584. fs.makeDir( ".osCache" )
  585. addLoading( "Creating User Folder" )
  586. fs.makeDir( ".osCache/users" )
  587. addLoading( "Creating OS Main Class" )
  588. --Moved up :P
  589.  
  590. --Extras
  591. addLoading( "De-noobing ROM" )
  592. addLoading( "Emptying Trashcan" )
  593. addLoading( "Booting GLaDOS" )
  594. addLoading( "Attending Minecon" )
  595. addLoading( "Voting against SOPA" )
  596. --Complete :D
  597.  
  598. for i=progress,x-4 do
  599. addLoading( "Completing" )
  600. if math.random(1,4) == 4 then
  601. sleep(0.5)
  602. end
  603. end
  604.  
  605. addLoading( "Rebooting..." )
  606. sleep(1)
  607. os.reboot()
  608. end
Advertisement
Add Comment
Please, Sign In to add comment